Polynomial Curve Fitting
13 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!