passing extra params to fmincon: anonymous function vs old method

조회 수: 11 (최근 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 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