Info

This question is closed. Reopen it to edit or answer.

Error message using function fminunc

1 view (last 30 days)
Orongo
Orongo on 11 Apr 2018
Closed: Orongo on 12 Apr 2018
Hi, I'm using the function fminunc to find my least square error. Unfortunately I get the error message
Error using fminusub (line 16)
Objective function is undefined at initial point. Fminunc cannot continue.
Error in fminunc (line 457)
[x,FVAL,GRAD,HESSIAN,EXITFLAG,OUTPUT] = fminusub(funfcn,x, ...
I understand the error can be caused by an inf or nan value, however I don't this applicable to me (??). My program for generation born 1938 looks like (the other generations result in same error message):
fun_1938=@(param)f_Makeham(param, mu_perks_1938, 1938);
param0_1938 = [2.06441912000572E-07/1000,0.197642212387667/100000,1.23947876070978/10];
[param_1938, fval_1938]=fminunc(fun_1938,param0_1938);
where
function res = f_Makeham(param,mu_perks,year)
a0=param(1);
b0=param(2);
c0=param(3);
if year == 1938
x=(77.5:1:106.5)';
elseif year==1945
x=(70.5:1:106.5)';
elseif year==1955
x=(65.5:1:106.5)';
end
res=sum((a0+b0*exp(c0*x)-mu_perks).^2);
What is causing the error message? How can I error track this?

Answers (1)

Alan Weiss
Alan Weiss on 11 Apr 2018
The error is clear. Try to evaluate fun_1938(param0_1938) and you will find that it throws an error. Investigate the error using standard MATLAB debugging.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
Orongo
Orongo on 12 Apr 2018
I'm trying to do this but not getting anywhere.

Community Treasure Hunt

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

Start Hunting!