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.

 采纳的回答

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 个)

Matt J
Matt J 2012-11-21
编辑:Matt J 2012-11-21

1 个投票

Use LSQCURVEFIT if you have it.
Matt J
Matt J 2012-11-21
编辑:Matt J 2012-11-21
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.

类别

帮助中心File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by