Optimization with Fmincon command in Simulink

5 views (last 30 days)
Hello friends,
I am facing an errors when I try to use fmincon command in simulink. I have attached the simulink and the errors photo.
Corresponding block code for both system dynamics
function xfd1 = fcn(x1,u1)
A=[-2 1.2;-2 -4];
B=[1 0;0 1];
function xfd2 = fcn(x2,u2)
A=[-2 1.2;-2 -4];
B=[1 0;0 1];
The corresponding code of the u_desired block
function [u_desired1,u_desired2 ] = fcn(x1,x2)
A=[-2 1.2;-2 -4];
Optimization related code
function [ u1,u2] = fcn(u_desired1,u_desired2)
global x1 x2
u=zeros(4, 1);
x0 = zeros(4, 1);
u = fmincon(@fun,x0,[],[],[],[],[],[],@nonl,options);
function f=fun(u_desired)
f = (0.5*(( u-u_desired)'*(u- u_desired)));
function [c,ceq] = nonl(u_desired)
global x1 x2
ceq = [];
c = [
norm(x11 - x12) - 2*0.5+10+0.5
-(norm(x11 - x12)) + 2*0.5+0.5];
Maybe I should attach a part of the article for you. I mean:
"Decentralized Connectivity Maintenance with Time Delays using Control Barrier Functions "
Farshid R
Farshid R on 2 Oct 2022
Hello @ Bruno Luong
Thank you very much for taking the time to answer me.
U is the control input that should be given to the system. which is obtained from the solving optimization.
The U_desired is obtained from the designed controller and must be dependent on x, and the system is asked to determine. the U_desired with the constraints of the U value for the system according to the U_desired.
The parameters are obtained from the x variables that are considered from the dynamics of the system and all the parameters are known.
It means that when I run the Simulink function, it encounters errors. I thought my question might be vague, that's why I sent you a link to a question that had the same problem as me.
optimization: calling fmincon in Simulink (embedded block)

Sign in to comment.

Answers (0)


Find more on Parameter Estimation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!