Function for best fitting

I've got a set of data :Y(d). And I am trying to approximate this set for an polynomial function in the following form :
So the problem is to find the values of each constant : "a,b,c,e" , for the best fitting!
So does someone know an possible way to do it,maybe some function ?
Obs:The set of data is quite big , so by "multiple iterations" I don't think Matlab can process some rotine.

1 comentario

Azzi Abdelmalek
Azzi Abdelmalek el 21 de Nov. de 2012
It does'nt look like a polynomial function

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 21 de Nov. de 2012

1 voto

There are several ways to do it.
First, write your function as:
% a = B(1), b = B(2), c = B(3), e = B(4)
% Y(d)=(a+b*d)/(c + e*d^3)
Y = @(B,d) (B(1) + B(2).*d) ./ (B(3) + B(4).*d.^3);
then, with d as your dependent variable and y as your independent variable:
Beta0 = rand(4,1);
[Beta,R,J,CovB,MSE] = nlinfit(d, y, Y, Beta0); % Statistics Toolbox
or:
[Beta,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(Y, Beta0, d, y); % Optimization Toolbox (allows parameter constraints)
If you do not have access to the Statistics or Optimization Toolboxes, I suggest you use fminsearch and the examples in Curve Fitting via Optimization. (The documentation explains it better than I could.) In that example, replace the start_point line with:
start_point = rand(4,1);
and the FittedCurve line with:
FittedCurve = (params(1) + params(2).*xdata) ./ (params(3) + params(4).*xdata.^3);
which is the code for your function.

2 comentarios

Israel
Israel el 22 de Nov. de 2012
Thank you
Star Strider
Star Strider el 22 de Nov. de 2012
My pleasure!

Iniciar sesión para comentar.

Más respuestas (2)

Matt J
Matt J el 21 de Nov. de 2012
Editada: Matt J el 21 de Nov. de 2012

1 voto

Use LSQCURVEFIT if you have it.
Matt J
Matt J el 21 de Nov. de 2012
Editada: Matt J el 21 de Nov. de 2012

0 votos

If noise is sufficiently negligble, you could also rewrite the problem as a linear fitting:
d=d(:);
Y=Y(:);
w=ones(length(d),1);
A=[w,d,-Y, -Y.*d.^3];
[~,~,V]=svd(A);
abce=V(:,end);
If nothing else, this could generate a good initial guess for LSQCURVEFIT.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Nov. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by