using fmincon to optimize function including simultaneous equations
Ältere Kommentare anzeigen

My optmization goal is equation (14) to maximize U cell
The code has 3 m.file(s)
1)
function [x,fval]=main
% 4 X's
x0=[0.207;0.00003288;0.592;0.004];
lb=[0.1656;0.000026304;0.4736;0.0032];
ub=[0.2484;0.000039456;0.7104;0.0048];
%linear constrain
A=[];B=[];
Aeq=[];Beq=[];
[x,fval]=fmincon(@objfunc,x0,A,B,Aeq,Beq,lb,ub,@confunc);
end
2)
function f=objfunc(x)
F=96485.4;a=0.051;b=0.663;R=8.3144;T=303;Va=0.000055;Vc=0.000055;XIn=0;
AcIn=1.56;OIn=0.3125;Am=0.0005;Fx=10;Yac=0.05;Kdec=0.000833;Ca=400;
Cc=500;Qa=0.0000225;Qc=0.0111;
q1=x(1)*exp((a*F*q3)/(R*T))*(q5*q7/(x(3)+q5)); %eq1
q2=-x(2)*(q6/(x(4)*q6))*exp(((b-1)*F*q4)/(R*T)); %eq2
0=Qa*(AcIn-q5)-(Am*q1); %eq3
0=(Qa*((XIn-q7)/Fx))+(Am*Yac*q1)-(Va*Kdec*q7); %eq4
0=Qc(OIn-q6)+q2*Am; %eq5
0=(3600*q8)-(8*F*q1);%eq6
0=(3600*q8)-(4*F*q2);%eq7 %
U0=0.77;dm=0.0001778;dcell=0.022;kaq=5;km=17;
f=U0-q3+q4-(((dm/km)+(dcell/kaq))*q8);
end
3)
function [c,ceq]=confunc(x)
F=96485.4;a=0.051;b=0.663;R=8.3144;T=303;Va=0.000055;Vc=0.000055;XIn=0;
AcIn=1.56;OIn=0.3125;Am=0.0005;Fx=10;Yac=0.05;Kdec=0.000833;Ca=400;
Cc=500;Qa=0.0000225;Qc=0.0111;
ceq=[Qa*(AcIn-q5)-(Am*q1);(Qa*((XIn-q7)/Fx))+(Am*Yac*q1)-(Va*Kdec*q7);Qc(OIn-q6)+q2*Am;(3600*q8)-(8*F*q1);(3600*q8)-(4*F*q2)];
c=[];
end
Can anyone enlighten me on what I might made wrong
2 Kommentare
John D'Errico
am 5 Mär. 2020
Note that you cannot use fmincon to force the parameters to be integers. You seem to have indicated that in your problem statement, but it is not clear.
Husam Mahmoud
am 5 Mär. 2020
Antworten (2)
These lines are illegal in Matlab. You cannot put a literal number like 0 on the left hand side of an '=', except when working with symbolic equations, which would not be appropriate here.
0=Qa*(AcIn-q5)-(Am*q1); %eq3
0=(Qa*((XIn-q7)/Fx))+(Am*Yac*q1)-(Va*Kdec*q7); %eq4
0=Qc(OIn-q6)+q2*Am; %eq5
0=(3600*q8)-(8*F*q1);%eq6
0=(3600*q8)-(4*F*q2);%eq7 %
If these are meant to represent equations that your solution must satisfy, they should go in confunc as additional equality constraints.
1 Kommentar
Husam Mahmoud
am 5 Mär. 2020
Bearbeitet: Husam Mahmoud
am 5 Mär. 2020
Walter Roberson
am 5 Mär. 2020
1 Stimme
You do not have simultaneous variables. You have a system of differential equations that are functions of time, but you are attempting to optimize as if the system was timeless.
You appear to working on chemical reactions. It might hypothetically make sense to optimize steady state, and it might hypothetically make sense to optimize over a limited time, but either way you would need to give time for the system to evolve with an ode solver, which you are not doing at all.
3 Kommentare
Husam Mahmoud
am 5 Mär. 2020
Walter Roberson
am 5 Mär. 2020
Is the idea that when you reach the steady state, the function stops changing, so its derivative becomes 0, so the left side of the differential equations become 0?
If so then you should probably use fsolve() on the system of expressions.
Husam Mahmoud
am 5 Mär. 2020
Bearbeitet: Husam Mahmoud
am 5 Mär. 2020
Kategorien
Mehr zu Choose a Solver finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!