can if conditions be used for equality constraint in fmincon?
3 次查看(过去 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!