fmincon in matlab function in simulink model

7 vues (au cours des 30 derniers jours)
Benjamin Pommer
Benjamin Pommer le 28 Août 2023
Commenté : Benjamin Pommer le 22 Sep 2023
Dear Matlab community
I am facing the following issue. I have a simulink model with three parallel aligned, self programmed MPCs. Those MPCs were designed fmincon and solve an optimization problem with constraints on the amplitude of the input.
However, after the simulation takes a decent amount of time to finally execute the error message that at sec 0.0 the model was ill-defined.
In order to deal with fmincon, the whole function was outsourced to an external file to deal with the compiler.
How do you solve this problem?
%%%Code of the matlab function
function du_llm1 = fcn(Yref,x,dztrack,PhiU1,PhiZ1,F1,H1,Qy1,y2,fuzzy_menge,b,Nc,dUmin,Umin,dUmax,Umax,Ymin,Ymax,M_du,M_u,C1)
nu = 3;
dU1 = zeros(nu*Nc,1);
du_llm1 = zeros(nu,1);
coder.extrinsic('opt_solv1');
if y2 <= fuzzy_menge(1,2)-b
du_llm1 = opt_solv1(dU1,H1,PhiU1,M_u,M_du,dUmin,dUmax,Umin,Umax,C1,du_llm1,Ymin,Ymax,x,F1,PhiZ1,dztrack,Qy1,Yref,nu);
end
end
%%%Code of the opt_solv1 containing fmincon and the defined constraints
function du_llm1 = opt_solv1(dU1,H1,PhiU1,M_u,M_du,dUmin,dUmax,Umin,Umax,C1,du_llm1,Ymin,Ymax,x,F1,PhiZ1,dztrack,Qy1,Yref,nu)
M_y = [-PhiU1; PhiU1];
M1 = [M_u;M_du;M_y];
gamma_du = [-dUmin; dUmax];
gamma_u = [ -Umin + C1*du_llm1; Umax - C1*du_llm1];
gamma_y = [ -Ymin + F1*x + PhiZ1*dztrack; Ymax - F1*x - PhiZ1*dztrack];
gamma1 = [gamma_u;gamma_du;gamma_y];
M1(isnan(gamma1),:) = [];
gamma1(isnan(gamma1)) = [];
f1 = -PhiU1' * Qy1 * ( Yref - F1*x - PhiZ1*dztrack);
options = optimoptions('fmincon', 'Algorithm', 'sqp');
options.MaxIterations = 1000;
options.OptimalityTolerance = 1e-5;
options.ConstraintTolerance = 1e-5;
dU1 = fmincon(@(dU1) ((Yref-F1*x)'*Qy1*(Yref-F1*x)-2*dU1'*f1+dU1'*H1*dU1),dU1,M1,@(x,du_llm1) gamma1,[],[],[],[],[],options);
du_llm1 = dU1(1:nu,1);
end
  3 commentaires
Benjamin Pommer
Benjamin Pommer le 22 Sep 2023
Basically, there are supposed to be three parallel aligned MPCs which form a fuzzy MPC with output blending which provide the input for a non-linear system. Initially, I had worked with quadprog but it seemed like that quadprog cannot handle constraints for non-linear systems since they were always violated. Anyways, here are the screenshots of the simulink mode:
Benjamin Pommer
Benjamin Pommer le 22 Sep 2023

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by