function optimizationcstrclear 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); endfunction AAHydroclc;close all;clear all;p = parameter(); % get the parameters into the workspace
Delta_T_adiabat = p.dTadZulaufkonzentration = p.c_AA_0x0 = [5;5];options= optimoptions('fsolve','Display','iter'); % Option to display output
[x,fval] = fsolve(@(x)myfun(x,p), x0, options); % Call solver
endfunction [c,ceq]= mycon(x)p= parameter();c= (x(1)*p.rho_A.A)/(p.MAA*(x(1)+x(2)));ceq= myfun(x);endfunction 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; endfunction 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
MATLAB: Error not enough input arguements and user supplied objective function in fmincon
periraviteja@gmail.com
Related Question
- Error in ode15s (line 150) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in THT2 (line 46) [v,X] = ode15s(@(v,x)ODEfun(v,x,params),tspan,initcons);
- Warning: Imaginary parts of complex X and/or Y arguments ignored
- Use “solution converged to an infeasible point” as an input
- Fsolve – no solution found for system of equations (there should be one though)
- Fmincon
- Difficulty in calling values from main program to fsolve function
- How to solve this thefun/numel problem
Best Answer