Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error message using function fminunc

1 回表示 (過去 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 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 12 日
Possibly mu_perks_1938 is not defined.

回答 (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