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

11 vues (au cours des 30 derniers jours)
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 commentaires
darova
darova le 30 Avr 2020
I plotted yuor function
Is it possible that it doesn't have minimum?
Ola Debiec
Ola Debiec le 30 Avr 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]

Connectez-vous pour commenter.

Réponse acceptée

Alan Weiss
Alan Weiss le 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

Plus de réponses (0)

Catégories

En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by