error not enough input arguements and user supplied objective function in fmincon

2 views (last 30 days)
function optimizationcstr
clear all;
close all;
clc;
%%Optimization
A =[];
b =[];
Aeq =[];
beq =[];
lb = [0 0 813.5 310];
ub = [1.7e-6 9.4e-5 814.5 340];
x0 = [8.6667e-8 6.66667e-7 814 325];
options = optimset('Algorithm','interior-point','Hessian','bfgs',...
'AlwaysHonorConstraints','bounds');
nonlcon=@mycon;
[x]= fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
end
function AAHydro
clc;
close all;
clear all;
p = parameter(); % get the parameters into the workspace
Delta_T_adiabat = p.dTad
Zulaufkonzentration = p.c_AA_0
x0 = [5;5];
options= optimoptions('fsolve','Display','iter'); % Option to display output
[x,fval] = fsolve(@(x)myfun(x,p), x0, options); % Call solver
end
function [c,ceq]= mycon(x)
p= parameter();
c= (x(1)*p.rho_A.A)/(p.MAA*(x(1)+x(2)));
ceq= myfun(x);
end
function dx = myfun(x,p)
% x(1) = Concnetration in the reactor
% x(2) = Temperature of reactor
dx = [0;0]; % initialize
dx(3) = (p.c_AA_0-x(3))/p.tau + p.kinf*exp(-p.EA/(p.R*x(4)))*(x(3))^p.n;
dx(4) = (p.Tin - x(4))/p.tau + p.dTad*p.kinf*exp(-p.EA/(p.R*x(4)))*(x(3))^p.n;
end
function p = parameter()
% Parameter
p.kinf= 936589 ; %[1/s]
p.EA= 49900; %[J/mol]
p.Rg= 8.314 ; %[J/mol*K]
p.V= 0.00026533 ; %[m3]
p.F_H2o=6.6667e-7; % m3/s Flowrate of H2o
p.F_A.A= 8.6667e-8; % m3/s Flowrate of A.A
p.F_Total= 7.53333e-7 ;% m3/s Total Flowrate
p.c_AA_0= 814 ; %[mol/m3] initial concentration
p.Delta_HR= -56.6 ;%[kJ/mol]
p.rho_cp= 4184 ;%[kJ/K*m3]
p.n=0.94 ; % reaction order
p.theTaw = 25; %0C mean temperature
p.theTao = 20; %0C initial temp in the reactor
p.Taw=p.theTaw+273.15;
p.Tao=p.theTao+273.15;
p.MAA=0.10209; % kg/mol
p.rho_A.A= 1080; % kg/m3
p.tau= p.V/p.F_Total;
p.dTad= -p.Delta_HR*p.c_AA_0/(p.rho_cp);
end

Accepted Answer

Walter Roberson
Walter Roberson on 25 Nov 2015
[x] = fmincon(@(x) myfun(x,p), x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
  1 Comment
raviteja peri
raviteja peri on 25 Nov 2015
I'm afraid, it still shows error. Failure in user supplied objective function evaluation. Fmincon cannot continue :(

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!