Error: Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.

조회 수: 3 (최근 30일)
Hi there,
I am trying to optimize my objective function with the following code:
function f = objectivefun(a)
lamblist = linspace(1,10,20);
Cauchy11 = [0 827982.753091953 1572844.18031762 2464184.69382751 3534322.19181553 4790513.14500519 6234910.15607021 7868283.55773547 9690949.15151327 11703050.5018082 13904658.4131231 16295810.1862600 18876526.5732673 21646819.6614556 24606696.7723621 27756162.4933249 31095219.7846345 34623870.6068982 38342116.2889111 42249957.7500000];
f = 0.0;
for i = 1:20
f = f + 2*(a(1)*(lamblist(i)^a(2)-(lamblist(i))^(-2*a(2)))-Cauchy11(i))^2;
end
end
Optimization Operation:
x0 = [4.225*10^5,2];
options = optimoptions('fminunc','GradObj','on');
[x,fval,gradient] = fminunc('objectivefun',x0,options)
The error that keeps coming up:
Error using objectivefun
Too many output arguments.
Error in fminunc (line 262)
[f,GRAD] = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.
Does anyone have any clue as to why this is happening? Thank you!

답변 (1개)

Walter Roberson
Walter Roberson 2015년 10월 20일
If you can compute the gradient of fun and the GradObj option is set to 'on', as set by
options = optimoptions('fmincon','GradObj','on')
then fun must return the gradient vector g(x) in the second output argument.
You set GradObj but your objective function does not return two outputs.
By the way: it is time to switch to function handles.
[x,fval,gradient] = fminunc(@objectivefun,x0,options)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by