Info

此问题已关闭。 请重新打开它进行编辑或回答。

Error message using function fminunc

2 次查看(过去 30 天)
Orongo
Orongo 2018-4-11
关闭: Orongo 2018-4-12
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?

回答(1 个)

Alan Weiss
Alan Weiss 2018-4-11
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 个评论
Orongo
Orongo 2018-4-12
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!

Translated by