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

采纳的回答

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