optimization with sqp algorithm

18 次查看(过去 30 天)
Sarah Kern
Sarah Kern 2020-1-27
评论: Alan Weiss 2020-1-29
Why doesnt the sqp algorithm works on my oprimization problem?
function [ Fx1, Fx2, Fx3, Fx4, alpha1, alpha2, alpha3, alpha4] = fcn(Fx_v, Fy_v, Mz_v, P_max_1, P_max_2, P_max_3, P_max_4, M_reg_1, M_reg_2, M_reg_3, M_reg_4, k, delta_T_aA, SW_1, SW_2, SW_3, SW_4, w_1, w_4, w_3, w_2, d_delay_1, d_delay_2, d_delay_3, d_delay_4, r_dyn_1, r_dyn_2, r_dyn_3, SOC_1, SOC_2, r_dyn_4, SOC_3, SOC_4, f_lag, n, j,w_vr, w_vl, w_hr, w_hl, l_h, l_v, c_w,d_min_vl, d_max_vl, d_min_vr, d_max_vr, d_min_hl, d_max_hl, d_min_hr, d_max_hr, A, B, FxB_max, SOC_krit, C, x0)
fun = @(x) C*((Fx_v-(x(1)*cos(x(5)+SW_1)+x(2)*cos(x(6)+SW_2)+x(3)*cos(x(7)+SW_3)+x(4)*cos(x(8)+SW_4)-x(5)*sin(x(5)+SW_1)*c_w-x(6)*sin(x(6)+SW_2)*c_w-x(7)*sin(x(7)+SW_3)*c_w-x(8)*sin(x(8)+SW_4)*c_w))^2+ (Fy_v-(x(1)*sin(x(5)+SW_1)+x(2)*sin(x(6)+SW_2)+x(3)*sin(x(7)+SW_3)+x(4)*sin(x(8)+SW_4)+x(5)*cos(x(5)+SW_1)*c_w+x(6)*cos(x(6)+SW_2)*c_w+x(7)*cos(x(7)+SW_3)*c_w+x(8)*cos(x(8)+SW_4)*c_w))^2+ (Mz_v-(x(1)*(-cos(x(5)+SW_1)*w_vl+l_v*sin(x(5)+SW_1))+x(2)*(cos(x(6)+SW_2)*w_vr+sin(x(6)+SW_2)*l_v)+x(3)*(-cos(x(7)+SW_3)*w_hl-l_h*sin(x(7)+SW_3))+x(4)*(cos(x(8)+SW_4)*w_hr-sin(x(8)+SW_4)*l_h)+x(5)*(sin(x(5)+SW_1)*c_w*w_vl+cos(x(5)+SW_1)*c_w*l_v)+x(6)*(-sin(x(6)+SW_2)*c_w*w_vr+cos(x(6)+SW_2)*c_w*l_v)+x(7)*(sin(x(7)+SW_3)*c_w*w_hl-cos(x(7)+SW_3)*c_w*l_h)+x(8)*(-cos(x(8)+SW_4)*c_w*l_h-sin(x(8)+SW_4)*c_w*w_hl)))^2); %(f_lag >= 0).*((A/SOC_1)*(x(1))^2+(A/SOC_2)*(x(2))^2+(A/SOC_3)*(x(3))^2+(A/SOC_4)*(x(4))^2+(d_delay_1-(SW_1+x(5)))^2+(d_delay_2-(SW_2+x(6)))^2+(d_delay_3-(SW_3+x(7)))^2+(d_delay_4-(SW_4+x(8)))^2) + (f_lag == -1).*((((B*(M_reg_1/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_1)*(1/(x(1)^2)))+(((B*(M_reg_2/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_2)*(1/(x(2)^2)))+(((B*(M_reg_3/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_3)*(1/(x(3)^2)))+(((B*(M_reg_4/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_4)*(1/(x(4)^2)))+(d_delay_1-(SW_1+x(5)))^2+(d_delay_2-(SW_2+x(6)))^2+(d_delay_3-(SW_3+x(7)))^2+(d_delay_4-(SW_4+x(8)))^2);
A = [];
b = [];
Aeq = [ 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0];
if f_lag == -1
%if it is possible the regenerative braking torque is the limit
% sum of the Force from the regenerative braking torque in vehiclecoordinates is bigger than the demanded force for the whole vehicle
% M_reg is always positive and Fx_v can be either positive or negative in the braking case
if (cos(SW_1)*(M_reg_1/r_dyn_1)+cos(SW_2)*(M_reg_2/r_dyn_2)+cos(SW_3)*(M_reg_3/r_dyn_3)+cos(SW_3)*(M_reg_4/r_dyn_4))> abs(Fx_v)
% max. regenerative braking torque
lb = [-M_reg_1/r_dyn_1, -M_reg_2/r_dyn_2, -M_reg_3/r_dyn_3, -M_reg_4/r_dyn_4, d_min_vl-SW_1, d_min_vr-SW_2, d_min_hl-SW_3, d_min_hr-SW_4]; %d and betato the left side are positive, to the right side are negative %regenerative braking torque must be positive
ub = [M_reg_1/r_dyn_1, M_reg_2/r_dyn_2, M_reg_3/r_dyn_3, M_reg_4/r_dyn_4, d_max_vl-SW_1, d_max_vr-SW_2, d_max_hl-SW_3, d_max_hr-SW_4];
else
% mechanical braking
%FxB_max is positive
lb = [-FxB_max, -FxB_max, -FxB_max, -FxB_max, d_min_vl-SW_1, d_min_vr-SW_2, d_min_hl-SW_3, d_min_hr-SW_4]; %d and betato the left side are positive, to the right side are negative %FxB_max is negative
ub = [FxB_max, FxB_max, FxB_max, FxB_max, d_min_vl-SW_1, d_min_vr-SW_2, d_min_hl-SW_3, d_min_hr-SW_4];
end % close conditions for braking loop, max braking torque is positive
%driving mode
else
lb = [-P_max_1/(r_dyn_1*w_1), -P_max_2/(r_dyn_2*w_2), -P_max_3/(r_dyn_3*w_3), -P_max_4/(r_dyn_4*w_4), d_min_vl-SW_1, d_min_vr-SW_2, d_min_hl-SW_3, d_min_hr-SW_4];
ub = [P_max_1/(r_dyn_1*w_1), P_max_2/(r_dyn_2*w_2), P_max_3/(r_dyn_3*w_3), P_max_4/(r_dyn_4*w_4), d_max_vl-SW_1, d_max_vr-SW_2, d_max_hl-SW_3, d_max_hr-SW_4];
end
%ub = (1:8);
nlcon = @nonlnconstraints;
%options = optimoptions(@fmincon, 'MaxFunctionEvaluations',10.000000e+03);
options = optimoptions(@fmincon, 'Algorithm', 'sqp');
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nlcon(Fx_v,Fy_v,Mz_v,SW_1,SW_2,SW_3,SW_4,w_vr, w_vl, w_hr, w_hl, l_h, l_v, c_w),options);
the problem works with the interior point algorithm, but the matlab function block, wont let me use it.
Any ideas, how I can make my problem work with the sqp algorithm?
Thank you very much!
  2 个评论
Matt J
Matt J 2020-1-27
How do we know that sqp doesn't work?
Alan Weiss
Alan Weiss 2020-1-29
Why do you have an all-zero Aeq? Looks like a mistake. And I don't see your definition of beq.
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Energy Storage 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by