How to connect the simulink to fmincon? Thanks
Show older comments
Hello, everyone. I am a matlab learner. I have some proble associated with the combination with the simulink and fmincon. Thank you for any suggestion and helps.
Here is the code:
function main
close all; clc;
x0=[1.6 100];
Lbnd=[0.5 90] ;
Ubnd=[2.5 450] ;
[x,y,exitflag,output]=fmincon(@objtime,x0,[],[],[],[],Lbnd,Ubnd,@Constt)
end
function ftime=objtime(x)
Kpi=x
options = simset('SrcWorkspace','current');
[t,xstatus,y]=sim('control_a2')
ftime=y(:,3)
end
function [C,Ceq]=Constt(x)
C(1)=x(1)-2.5
C(2)=0.5-x(1)
C(3)=x(2)-450
C(4)=50-x(2)
Ceq=[]
end
The simulink is called in object function. But when I run the code. The "x" design variables are not changed. The optimization is not implemented. I am not sure whether is related with the workspace problem or with other aspects? Could you give me some idea and solution?
Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on General Applications 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!