Info
This question is closed. Reopen it to edit or answer.
Fmincon tries the same values for manipulated variables for three iterations
1 view (last 30 days)
Show older comments
Hello, I have a simulink model that I control and minimize one of its outputs with fmincon. My problem is that fmincon tries two values for the two manipulated variables for three iterations before changing to another guess. The optimization in other words is three times slower. I've tried to change the Algorithm with no result. How can I fix this?
Here is my code:
options=optimset('Algorithm','sqp','TolX',0.01,'TolFun',0.001);
x=fmincon(@obj,xo,A,B,[],[],xmin,xmax,[],options);
function q = obj(z)
cr=z(1);
tr=z(2);
sopt = simset('solver','ode3','SrcWorkspace','base','DstWorkspace','base','SaveFormat','Array');
[~,~,yo]= sim('sgs2.slx',[0 1], sopt);
q=abs(yo(end,1)-yo(end,2));
end
0 Comments
Answers (2)
John D'Errico
on 18 Jan 2015
Edited: John D'Errico
on 18 Jan 2015
Are they really IDENTICAL? Somehow I doubt it. Look more carefully. Perhaps you need to write out the parameters with more precision.
Fmincon must compute a gradient. So this means it must make a tiny adjustment to each parameter, to then compute an approximate derivative. Once it gets an estimate of the local gradient, it can then take an actual step. At some point, it will then decide it need to know the gradient again. So it does so.
You cannot magically make it run more quickly. Knowledge of the gradient allows it to make an INTELLIGENT choice for the next place to look. For example, you might use fminsearch instead, a solver that does not need to compute a gradient. But that lack of information costs you greatly, so it will converge more slowly and less reliably.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!