fmincon error while running
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
Hello, can someone help me please,
I am desperate and have no futher ideas.
i have an optimization problem and always get an error while running back.
Thats my 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, C, FxB_max, SOC_crit, P_min_1, P_min_2, P_min_3, P_min_4)
%Parameterdefinition
%definition of vehicle forces and torque
%case decision
% if f_lag > 0 % decision braking or driving mode
% fun =@(x) (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))+d_delay_2-(SW_2+x(6))+d_delay_3-(SW_3+x(7))+d_delay_4-(SW_4+x(8));
fun =@(x) (A/SOC_1)*(x(1))^2+(A/SOC_2)*(x(2))^2+(A/SOC_3)*(x(3))^2+(A/SOC_4)*(x(4))^2;
% else
% fun =@(x) ((B*M_reg_1)/SOC_1)*(1/(x(1))^2)+((B*M_reg_2)/SOC_2)*(1/(x(2))^2)+((B*M_reg_3)/SOC_3)*(1/(x(3))^2)+((B*M_reg_4)/SOC_4)*(1/(x(4))^2)+d_delay_1-(SW_1+x(5))+d_delay_2-(SW_2+x(6))+d_delay_3-(SW_3+x(7))+d_delay_4-(SW_4+x(8));
% end
%objektive function
x0 = [Fx_v/4,Fx_v/4,Fx_v/4,Fx_v/4,(d_delay_1-SW_1),(d_delay_2-SW_2),(d_delay_3-SW_3),(d_delay_4-SW_4)];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [P_min_1, P_min_2, P_min_3, P_min_4, d_min_vl-SW_1, d_min_vr-SW_2, d_min_hl-SW_3, d_min_hr-SW_4];
ub = (1:8);
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];
nlcon = @nonlnconstraints;
%options = optimoptions(@fmincon, 'MaxFunctionEvaluations',10.000000e+03);
options = optimoptions(@fmincon, 'Algorithm', 'sqp-legacy');
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);
%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));
Fx1 = x(1);
Fx2 = x(2);
Fx3 = x(3);
Fx4 = x(4);
alpha1 = x(5);
alpha2 = x(6);
alpha3 = x(7);
alpha4 = x(8);
end
with this non linear constraints
function [c,ceq] = nonlnconstraints(Fx_v,Fy_v,Mz_v,SW_1,SW_2,SW_3,SW_4,c_w,l_v,l_h,w_hl,w_hr,w_vl,w_vr)
ceq =@(x) [Fx_v-(x(1)*cos(x(1)+SW_1)+x(2)*cos(x(2)+SW_2)+x(3)*cos(x(3)+SW_3)+x(4)*cos(x(4)+SW_4)-x(5)*sin(x(1)+SW_1)*c_w-x(6)*sin(x(2)+SW_2)*c_w-x(7)*sin(x(3)+SW_3)*c_w-x(8)*sin(x(4)+SW_4)*c_w); Fy_v-(x(1)*sin(x(1)+SW_1)+x(2)*sin(x(2)+SW_2)+x(3)*sin(cos(x(3)+SW_3)+x(4)*sin(x(4)+SW_4)-x(5)*cos(x(1)+SW_1)*c_w-x(6)*cos(x(2)+SW_2)*c_w-x(7)*cos(x(3)+SW_3)*c_w-x(8)*cos(x(4)+SW_4)*c_w)); Mz_v-(x(1)*(cos(x(1)+SW_1)*w_vl-l_v*sin(x(1)+SW_1))+x(2)*(-cos(x(2)+SW_2)*w_vr+sin(x(2)+SW_2)*l_v)+x(3)*(cos(x(3)+SW_3)*w_hl+l_h*sin(x(3)+SW_3))+x(4)*(-cos(x(4)+SW_4)*w_hr+sin(x(4)+SW_4)*l_h)+x(5)*(sin(x(1)+SW_1)*c_w*w_vl+cos(x(1)+SW_1)*c_w*l_v)+x(6)*(sin(x(2)+SW_2)*c_w*w_vr+cos(x(2)+SW_2)*c_w*l_v)+x(7)*(-sin(x(3)+SW_3)*c_w*w_hl-cos(x(3)+SW_3)*c_w*l_h)+x(8)*(cos(x(4)+SW_4)*c_w*l_h+sin(x(4)+SW_4)*c_w*w_hl))];
c = [];
end
and I get this error after simulink calculated for a while
An error occurred while running the simulation and the simulation was terminated
Caused by:
Objective or nonlinear constraint undefined at initial point. Fmincon cannot continue.
Error in 'FTR_diskret/CarMaker/VehicleControl/FTR1/Fahren/Aufteilung der Überaktuierung /Kräfteaufteilung/linearer Fahrbereich/MATLAB Function' (line 103)
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);
Hopefully someone has an idea,
thank you very much
Antworten (0)
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!