How to control simulink with fmincon using 2 (two) decision variables
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I have a simulink file that I want to control. I want to minimize my objective:
function q = obj(cr,tr) % cr, tr are the variables that I want to be manipulated
sopt = simset('solver','ode3','SrcWorkspace','base','DstWorkspace','base','SaveFormat','Array');
[~,~,yo]= sim('sgs2.slx',[0 10], sopt);
q=abs(yo(end,1)-yo(end,2));
end
I call fmincon
x=fmincon(@obj,xo,[],[],[],[],xmin,xmax,[],options);
the optimization runs but fails.
I think that the way that passing the decision variables is wrong but I have no idea what to try.
0 件のコメント
回答 (1 件)
Titus Edelhofer
2014 年 11 月 13 日
Hi,
do you have other variables in your model apart from cr and tr? If not, you should select 'current' for SrcWorkspace and DstWorkspace. This way Simulink would grab the variables cr and tr from the input variables.
Second: your objective function needs to be declared differently. It must have the form obj(x) where x is a vector (of size two in your case). So you would need to change
function q = obj(x)
cr = x(1);
tr = x(2);
Titus
4 件のコメント
Stefanos Kalandaridis
2014 年 11 月 13 日
Stefanos Kalandaridis
2014 年 11 月 13 日
Titus Edelhofer
2014 年 11 月 13 日
Yes, I do: the values are not exactly the same, but very similar. For the jacobian it computes the finite differences
df/dcr ~ (f(cr+h, tr)-f(cr,tr))/h
and
df/dtr ~ (f(cr, tr+h)-f(cr,tr))/h.
So you see three (similar but not equal) calls to f for each iteration. More generally, for n variables you need n+1 function evaluations per iteration (neglecting the fact that the optimizer sometimes updates the jacobian without recomputing it).
Titus
Stefanos Kalandaridis
2014 年 11 月 15 日
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!