Getting min value from fminunc

I'm using the function fminunc to find the minimum in square difference. The code I have is
fun=@(param)f_Makeham(param,mu_perks_1938);
param0 = [0,0.2,1.2];
[S2, fval]=fminunc(fun,param0);
function res = f_Makeham(param,mu_perks_1938)
a0=param(1);
b0=param(2);
c0=param(3);
x=(77.5:1:100.5)';
res=sum((a0+b0*exp(c0*x)-mu_perks_1938).^2);
This result in fval=9.8674e+59 which is clearly not small at all. I understand the function fminunc is to find the minimum of the function. Please help here, I don't see where I'm going wrong here. I amended the question with a figure of mu_perks_1938.

1 comentario

Walter Roberson
Walter Roberson el 27 de Mzo. de 2018
I would suggest to you that you should be using the Curve Fitting Toolbox for this.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 29 de Mzo. de 2018

1 voto

"This result in fval=9.8674e+59 which is clearly not small at all."
No, it is really quite good for that formula and that range of x values. With the starting values you give, a0+b0*exp(c0*x) ranges from 4.90249108584017e+39 to 4.75274499526166e+51. Suppose that your mu_perks_1938 were almost exactly those, but there was a single bit round-off error. That gives eps() in the range 6E+23 to 6E+35. square those, sum them, and you would get 4.76686006670123e+71 . So the expected residue for as close of a fit as you could realistically hope to get with those parameters is about 5E11 times larger than the residue you are seeing. Either you are getting quite lucky on matching data values bit-for-bit, or else the optimization is able to find a better fit by over 10 orders of magnitude.
Birdman
Birdman el 27 de Mzo. de 2018
I believe the exponential term in your function should be decaying as follows:
res=sum((a0+b0*exp(-c0*x)-mu_perks_1938).^2);

4 comentarios

John D'Errico
John D'Errico el 27 de Mzo. de 2018
Without actually seeing the data, I think Birdman is probably correct. It would really help to see the data, even if only a plot of the data.
Walter Roberson
Walter Roberson el 27 de Mzo. de 2018
However with fminunc then it should have tried negative values for param(3) so it should not matter.
Torsten
Torsten el 28 de Mzo. de 2018
The y-data are increasing with x, thus c0 should be positive:
https://de.mathworks.com/matlabcentral/answers/390707-equivalent-of-excel-solver-fminunc
Best wishes
Torsten.
Orongo
Orongo el 29 de Mzo. de 2018
Unfortunately I can't change the formula to res=sum((a0+b0*exp(-c0*x)-mu_perks_1938).^2); because the formula is given (Makeham).

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 27 de Mzo. de 2018

Respondida:

el 29 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by