can if conditions be used for equality constraint in fmincon?

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];

 Akzeptierte Antwort

John D'Errico
John D'Errico am 4 Jul. 2022
Bearbeitet: John D'Errico am 4 Jul. 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_lo = 
Kba_hi = (1-(2*(u2-SOCoptimal))/(0.9-0.4))^20
Kba_hi = 
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 Kommentar

aditya deepak
aditya deepak am 5 Jul. 2022
Bearbeitet: aditya deepak am 5 Jul. 2022
Thank you.
Will pattern search work Or GA is the only option?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by