Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Error message using function fminunc

1 visualización (últimos 30 días)
Orongo
Orongo el 11 de Abr. de 2018
Cerrada: Orongo el 12 de Abr. de 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?
  1 comentario
Walter Roberson
Walter Roberson el 12 de Abr. de 2018
Possibly mu_perks_1938 is not defined.

Respuestas (1)

Alan Weiss
Alan Weiss el 11 de Abr. de 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 comentario
Orongo
Orongo el 12 de Abr. de 2018
I'm trying to do this but not getting anywhere.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by