passing extra params to fmincon: anonymous function vs old method

12 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Direct Search 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by