fminunc stopped because it cannot decrease the objective function along the current search direction.

조회 수: 11 (최근 30일)
Hi, I'm trying to use fminunc function with the gradient but it doesn't work properly.
my start point is: [1.5;-2.5]
this is my objective function:
function [f, g, H] = rosenboth(x)
% Calculate objective f
a = 0.5;
b = -1.5;
f = (1 - x(1) + a)^2 + 100 * (x(2) - b - (x(1) - a)^2)^2;
if nargout > 1 % gradient required
g = [2 * (-200 * (x(1) - 1) * (-x(1)^2 + 2 * x(1) + x(2)) + x(1) - 2);
200 * (-x(1)^2 + 2 * x(1) + x(2))];
if nargout > 2 % Hessian required
H = [1200 * x(1)^2 - 2400 * x(1) - 400 * x(2) + 802, -400 * (x(1) - 1);
-400 * (x(1) - 1), 200];
end
end
and that's the generated code from optimtool
function [x,fval,exitflag,output,grad,hessian] = fmin_gradient(x0,OptimalityTolerance_Data,StepTolerance_Data)
%% This is an auto generated MATLAB file from Optimization Tool.
%% Start with the default options
options = optimoptions('fminunc');
%% Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'OptimalityTolerance', OptimalityTolerance_Data);
options = optimoptions(options,'FunctionTolerance', OptimalityTolerance_Data);
options = optimoptions(options,'StepTolerance', StepTolerance_Data);
options = optimoptions(options,'PlotFcn', @optimplotfval);
options = optimoptions(options,'Algorithm', 'quasi-newton');
options = optimoptions(options,'SpecifyObjectiveGradient', true);
options = optimoptions(options,'Hessian', 'off');
[x,fval,exitflag,output,grad,hessian] = fminunc(@rosenboth,x0,options);
end
  댓글 수: 2
darova
darova 2020년 4월 30일
I plotted yuor function
Is it possible that it doesn't have minimum?
Ola Debiec
Ola Debiec 2020년 4월 30일
No, there shoukd be one. I’m also chcecking it with fminsearch and it works and shows the minimum at [1.5;-0.5]

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Weiss
Alan Weiss 2020년 5월 1일
Please run with the CheckGradients option set to true. I think that you will find that you did not calculate the derivatives correctly.
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by