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.

 Réponse acceptée

Star Strider
Star Strider le 21 Nov 2012

1 vote

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 commentaires

Israel
Israel le 22 Nov 2012
Thank you
Star Strider
Star Strider le 22 Nov 2012
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (2)

Matt J
Matt J le 21 Nov 2012
Modifié(e) : Matt J le 21 Nov 2012

1 vote

Use LSQCURVEFIT if you have it.
Matt J
Matt J le 21 Nov 2012
Modifié(e) : Matt J le 21 Nov 2012

0 votes

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.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by