Polynomial Curve Fitting

13 Ansichten (letzte 30 Tage)
Stephen Shortridge
Stephen Shortridge am 29 Mär. 2011
For my introductory MATLAB programming class, I need to create a function that fits an n'th order polynomial curve to given data using least squares method.
[fx,a] = curvepoly (x,y,n)
fx=y-axis values on the curve-fit corresponding to the cc-values
a=the polynomial coefficients found
x=[-4. -3.5 -3. -2.5 -2. -1.5 -1. -0.5 0. 0.5 1. 1.5 2. 2.5]
y=[0.0013 0.0026 0.0052 0.0106 0.0213 0.0429 0.0863 0.1739 0.35 0.7048 1.4193 2.8582 5.7556 11.5904]
n=order of polynomial desired
Please use the most basic syntax possible Thanks

Antworten (1)

Walter Roberson
Walter Roberson am 29 Mär. 2011
One "most basic syntax" function coming up:
function [fx,a]=curvefit(x,y,n)
a=polyfit(x,y,n)
fx=polyval(a,x)
  2 Kommentare
Stephen Shortridge
Stephen Shortridge am 29 Mär. 2011
I wish I could use that but I need to write a code that does what polyfit does.
Walter Roberson
Walter Roberson am 29 Mär. 2011
function [fx,a]=curvefit(x,y,n)
x=x(:);
for K=0:n-1
b(:,n-K)=x.^K;
end
a=b\y;
fx=polyval(a,x);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by