Polynomial Curve Fitting

13 ビュー (過去 30 日間)
Stephen Shortridge
Stephen Shortridge 2011 年 3 月 29 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 3 月 29 日
One "most basic syntax" function coming up:
function [fx,a]=curvefit(x,y,n)
a=polyfit(x,y,n)
fx=polyval(a,x)
  2 件のコメント
Stephen Shortridge
Stephen Shortridge 2011 年 3 月 29 日
I wish I could use that but I need to write a code that does what polyfit does.
Walter Roberson
Walter Roberson 2011 年 3 月 29 日
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);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by