Problem with optimization using fminunc + GradObj

2 views (last 30 days)
Hello,
I have problem with optimization using fminunc with GradObj set to on. I'm trying to find minimum in Rosenbrock function - which have only one minimum at [1.0, 1.0]. Without GradObj fminunc is ale to find optimum. With GradObj function stops after 3 iterations with message:
-----
First-order
Iteration Func-count f(x) Step-size optimality
0 1 24.2 211
1 3 4.25728 0.000871384 17.8
2 4 4.12914 1 3.16
Local minimum possible.
fminunc stopped because it cannot decrease the objective function
along the current search direction.
<stopping criteria details>
X =
-1.0306 1.0697
FVAL =
4.1291
EXITFLAG =
5
OUTPUT =
iterations: 3
funcCount: 22
stepsize: 1
firstorderopt: 3.1610
algorithm: 'medium-scale: Quasi-Newton line search'
message: [1x362 char]
-----
Here is code I'm running:
function [f,G] = func1(x)
f = (1 - x(1))*(1 - x(1)) + 100*(x(2) - x(1)*x(1))*(x(2) - x(1)*x(1));
% Gradient of the objective function
if nargout > 1
G = [-2 - 2*x(1) - 400*x(2)*x(1) + 400*x(1)*x(1)*x(1),
200*x(2) - 200*x(1)*x(1)];
end
end
...
options = optimset('LargeScale', 'off', 'InitialHessType', 'Scaled-Identity', 'GradObj', 'on', 'Display', 'iter');
% where startX = -1.2 and startY = 1.0
[X,FVAL,EXITFLAG,OUTPUT] = fminunc(@func1,[startX, startY], options)
Please, help me solve this problem.

Accepted Answer

Andrew Newell
Andrew Newell on 26 Jan 2012
It's a sign error. The gradient should be
G = [-2 + 2*x(1) - 400*x(2)*x(1) + 400*x(1)^3
200*x(2) - 200*x(1)^2];

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!