Optimization with Fmincon command in Simulink

3 次查看(过去 30 天)
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];
xfd1=A*x1+B*u1;
function xfd2 = fcn(x2,u2)
A=[-2 1.2;-2 -4];
B=[1 0;0 1];
xfd2=A*x2+B*u2;
The corresponding code of the u_desired block
function [u_desired1,u_desired2 ] = fcn(x1,x2)
A=[-2 1.2;-2 -4];
C=eye(2);
%%
u_desired1=(-C*A*x1);
u_desired2=(-C*A*x2);
Optimization related code
function [ u1,u2] = fcn(u_desired1,u_desired2)
coder.extrinsic('fmincon')
global x1 x2
u=zeros(4, 1);
x0 = zeros(4, 1);
optimoptions('fmincon','Display','iter','Algorithm','sqp');
u = fmincon(@fun,x0,[],[],[],[],[],[],@nonl,options);
u1=[u(1);u(2)];
u2=[u(3);u(4)];
function f=fun(u_desired)
f = (0.5*(( u-u_desired)'*(u- u_desired)));
function [c,ceq] = nonl(u_desired)
global x1 x2
x11=[x1(1);x1(2)];
x12=[x2(1);x2(2)];
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 "
  25 个评论
Bruno Luong
Bruno Luong 2022-10-2
I'm not familiar with "algebric connectivity", "CBF". What is "U" set?
In your model in the top,there is a fractional derivative I don' see it implemented anywhere, the t variable does not seem to present anywhere in your code. Why you set U dersired to something dependent to x? What is the known parameters what is not in your problem? What does exactly means "I can't do optimization in Simulink"? (I don't know simulink)
Sorry but I can't make a head and tail of this question. You might start to a new question again. I think I'm not alone to find the question nit not clearly described.
Farshid R
Farshid R 2022-10-2
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)
https://www.mathworks.com/matlabcentral/answers/65202-optimization-calling-fmincon-in-simulink-embedded-block

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Manual Performance Optimization 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by