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

11 Ansichten (letzte 30 Tage)
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 Kommentare
Ola Debiec
Ola Debiec am 30 Apr. 2020
No, there shoukd be one. I’m also chcecking it with fminsearch and it works and shows the minimum at [1.5;-0.5]

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 1 Mai 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by