Set Limits for x in optimization using fminunc

10 ビュー (過去 30 日間)
Sebastian Körner
Sebastian Körner 2020 年 12 月 15 日
編集済み: John D'Errico 2020 年 12 月 15 日
Hi, i am optimizing some parameters in my Simulink model by using the matlab function fminunc.
this works perfectly fine:
func = @(x) Main_run(x);
x0 = [5];
[x,fval] = fminunc(func,x0)
now i want to optimize the upper limit of a saturation block. but while running my optimization, matlab trys values for x that are below the lower limit of the saturation block, which results in the following error
Lower limit must be less than or equal to upper limit in 'MMSiL/ISG-Regelung/ISG Controller_Drehzahlregelung/Saturation'
So i am searching for a way to set a lower limit for the value assigned to the variable x. i tryed by using the options of fminunc but i dont think thats the right wy to do it.
x = fminunc(fun,x0,options)


Walter Roberson
Walter Roberson 2020 年 12 月 15 日
Never. fminunc literally has to do with UNConstrained. No chance of putting constraints on it.
Use fmincon instead.

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 12 月 15 日
編集済み: John D'Errico 2020 年 12 月 15 日
If you have fmincon, then you also have fmincon so there cannot be a problem. This is not a question of how to get fminunc to solve your problem, but of using the correct tool.
That said, COULD you solve a constrained probem using fminunc? Of course. If you understand how I wrote fminsearchbnd, then you can do the same thing for fminunc. Thus you would need to essentially modify the objective function. In fminsearchbnd, I did that by creating a wrapper around the objective function between the optimizer (fminsearch in that case) and the objective. You can find fminsearchbnd on the file exchange to learn how I solved that problem. This does create a transformed problem, introducing nonlinearities that typically introduce multiple solutions to the problem, all of which are identical in objective. As such, those alternative solutions are irrelevant because you don't care which one you find. The introduced nonlinearities can be important and problematic though, because they change the shape of your objective.
Anyway, is that worth doing here? Are you kidding? Why in the name of god and little green apples would you go through the effort, when a better solution is already available and works quite well?
Just use fmincon. It is surely better to learn how to use all of the tools in your toolbox, than to find ways to force one tool to solve problems it is not designed to solve well.


Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by