can if conditions be used for equality constraint in fmincon?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
aditya deepak
el 4 de Jul. de 2022
Editada: aditya deepak
el 5 de Jul. de 2022
Value of beq depends on the SOC [u(2)] which is one of the input to the S function in simulink. Could this be done?
%define Matrix Aeq
Aeq=[0 1 0;1 0 1];
%define Matrix beq
SOCoptimal = .5
if u(2)<=0.9 && u(2)>=0.4
Kba = (1-(2*(u(2)-SOCoptimal))/(0.9-0.4))^4;
else if u(2)<0.4 | u(2)>0.9
Kba = (1-(2*(u(2)-SOCoptimal))/(0.9-0.4))^20
else
;
end
H_consumption = out.simout;
m_average = mean (H_consumption);
Pfc_average = mean (Pfc)
m_ba = (Pbatt*m_average*0.55)/Pfc_average
beq=[Kba*m_ba; u(1)];
%define boundary conditions
lb=[Pfc_min, 0, -Pbatt_char];
ub=[Pfc_max, 100, Pbatt_max];
%define initial conditions
%x0=[Pfc_min, 0, 0];
x0=[3000, 0.1, 3000];
options = optimoptions('fmincon','Algorithm','active-set','Display','off','MaxFunctionEvaluations',1000,'MaxIterations',100);
[y,fval] = fmincon('OF_ECMS',x0,[],[],Aeq,beq,lb,ub,[],options); %#ok<*ASGLU>
Pfc=y(1); Pbatt=y(3); alpha=y(2);
sys = [Pfc Pbatt alpha];
0 comentarios
Respuesta aceptada
John D'Errico
el 4 de Jul. de 2022
Editada: John D'Errico
el 4 de Jul. de 2022
NO. That creates a non-differentiable equality constraint. Not even continuous.
For example, at u(2) == 0.4, what happens?
u2 = 0.4;
syms SOCoptimal
Kba_lo = (1-(2*(u2-SOCoptimal))/(0.9-0.4))^4
Kba_hi = (1-(2*(u2-SOCoptimal))/(0.9-0.4))^20
So depending on where u(2) lives, the equality constraint has two completely different shapes. In fact, it is not even continuous, because the two limits are not the same.
Can fmincon be used here? NO.
Instead, you will probably need to use a tool that is robust against such problems. I'd pick GA.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!