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!