passing extra params to fmincon: anonymous function vs old method

12 ビュー (過去 30 日間)
Amad
Amad 2012 年 9 月 7 日
Hi,
I was trying to pass extra parameters to fmincon function. I did it in two different ways: anonymous functions and old method, and I got 2 different results.
When I use anonymous functions, Matlab said that the initial point is already local minima. But when I use the old method, the optimization proceeds and run until the objective function x reaches f(x) = 0.0468.
Why is it like that? With this situation I prefer to use the old method to pass the extra parameters. However, the old method does not allow me add Output function to fmincon.
Thanks in advance. Amad
----------------
Anonymous function
Code:
myfun = @(k)funObj(kSearch,x0,ti,tP);
[kSearch,resnorm] = fmincon(myfun,kSearch,[],[],[],[],lb,ub,[],optionLSQ);
Output:
Max Line search Directional First-order
Iter F-count f(x) constraint steplength derivative optimality Procedure
0 51 0.0502957 0
Local minimum found that satisfies the constraints.
--------------------------
Old method:
Code:
[kSearch,resnorm] = fmincon(@funObj,kSearch,[],[],[],[],lb,ub,[],optionLSQ,x0,ti,tP);
Output:
Max Line search Directional First-order
Iter F-count f(x) constraint steplength derivative optimality Procedure
0 51 0.0502957 0
1 114 0.0502503 0 0.000244 -0.752 17.2
2 172 0.0495527 0 0.00781 -0.551 34.1
3 232 0.0494097 0 0.00195 -0.408 10.8

採用された回答

Alan Weiss
Alan Weiss 2012 年 9 月 7 日
The error is in this line of code:
myfun = @(k)funObj(kSearch,x0,ti,tP);
funObj does not have a variable k, so no matter what value of k is chosen, funobj always returns the same value. You probably meant to write
myfun = @(kSearch)funObj(kSearch,x0,ti,tP);
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Amad
Amad 2012 年 9 月 7 日
Hi Alan,
Thank you so much, your solution is really helpfull.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by