can if conditions be used for equality constraint in fmincon?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
John D'Errico
2022 年 7 月 4 日
編集済み: John D'Errico
2022 年 7 月 4 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!