Hi , I'm new to matlab with fsolve and I get not enough input arguments everytime. Can someone please as what am I missing. Many Thanks
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
raviteja peri
le 24 Nov 2015
Commenté : Alan Weiss
le 30 Nov 2015
function AAHydro
p = parameter;
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(@myfun, x0, options); % Call solver
end
function dx = myfun(x)
% x(1) = Concnetration in the reactor
% x(2) = Temperature of reactor
p= parameter;
dx(1) = (p.c_AA_0-x(1))/p.tau + p.kinf*exp(-p.EA*1000/(p.R*x(2)))*(x(1))^p.n;
dx(2) = (p.Tin - x(2))/p.tau + p.dTad*p.kinf*exp(-p.EA*1000/(p.R*x(2)))*x(1))^p.n;
dx = dx';
end
function p = parameter()
p.R = 8.3145; % [J/molK]
p.Tin = 30 + 273.15; % [K]
p.n = 0.94;
p.rho = 1000; % [kg/m^3]
p.cp = 4.186; % [kJ/kgK]
p.vol = 0.56; % [l]
p.dHr = -55.5; % [kJ/mol]
p.MAA = 102.09; % [g/mol]
p.rho_AA = 1.08; % [g/cm^3]
% p.Vdot_AA = 1.114 ; % [l/h]
p.Vdot_AA = 0.3 ; % [l/h]
p.Vdot_W = 3.6; % [l/h]
p.Vdot_total = p.Vdot_AA + p.Vdot_W; % [l/h]
p.tau = p.vol/p.Vdot_total*60*60; % [s]
p.c_AA_0 = ((p.Vdot_AA*p.rho_AA*1000)/p.MAA)/p.Vdot_total; % [mol/l]
p.dTad = -p.dHr*p.c_AA_0/(1e-03*p.rho*p.cp); % [K]
p.kinf = 139390; % [1/s]
p.EA = 44.35; % [kJ/mol]
end
0 commentaires
Réponse acceptée
Alan Weiss
le 24 Nov 2015
Perhaps you should pass your parameters as follows:
p = parameter(); % get the parameters into the workspace
[x,fval] = fsolve(@(x)myfun(x,p), x0, options); % Call solver
where you change the function myfun as follows:
function dx = myfun(x,p)
% x(1) = Concnetration in the reactor
% x(2) = Temperature of reactor
dx = [0;0]; % initialize
dx(1) = (p.c_AA_0-x(1))/p.tau + p.kinf*exp(-p.EA*1000/(p.R*x(2)))*(x(1))^p.n;
dx(2) = (p.Tin - x(2))/p.tau + p.dTad*p.kinf*exp(-p.EA*1000/(p.R*x(2)))*x(1))^p.n;
end
Alan Weiss
MATLAB mathematical toolbox documentation
2 commentaires
Alan Weiss
le 30 Nov 2015
If you are asking what the fmincon error means, you should know that fmincon requires the objective function to return a scalar value. This means not a vector or matrix, a scalar. You should check what your fmincon objective function returns for your initial value x0.
Alan Weiss
MATLAB mathematical toolbox documentation
Plus de réponses (1)
raviteja peri
le 25 Nov 2015
Modifié(e) : Walter Roberson
le 25 Nov 2015
4 commentaires
Stephen23
le 25 Nov 2015
Modifié(e) : Stephen23
le 25 Nov 2015
Sure, but this is an Answer. We can see that it is an answer because the text-field title was "Answer this question", where you posted the code. It helps us when you stick to using the comments for commenting and adding more information on your original question. The comment links are titled "Comment on this Answer" or "Comment on this Question".
You still have not asked a question, so it is not clear why you have shown us this code. IS the code doing something that you do not expect? How can we help you with it? It would be nice to get an explanation from you, as our mindreading abilities are not very well developed.
Walter Roberson
le 25 Nov 2015
The user posted the code in a new question which has received an answer.
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!