Creating a polynomial fit expression using just the order number

조회 수: 55 (최근 30일)
Jason
Jason 2025년 11월 18일 21:26
편집: dpb 2025년 11월 20일 16:37

Hello. Im performing a fit to data using e.g a 3rd order polynomial and the expresion below. For cases when i want e.g a 4th or 5th order fit, rather than use a switch / case approach is there a way to construct the expression below simply by passing in n the polynomial order?

a123 = [x.^3, x.^2, x]\y;

채택된 답변

dpb
dpb 2025년 11월 18일 21:38
편집: dpb 2025년 11월 18일 21:57
c=x.^[n:-1:1]\y;
I presume leaving off the intercept is intentional? Otherwise, there's polyfit
  댓글 수: 5
dpb
dpb 2025년 11월 19일 21:22
With a 7th order polynomial, are you forcing it through a set of points, maybe? Would a spline be an alternative?
Torsten
Torsten 2025년 11월 19일 23:53
편집: dpb 2025년 11월 20일 16:37
xtr=x-x0;
% acoeffs=[xtr.^5,xtr.^4,xtr.^3,xtr.^2,xtr]\(y-y0) %acoeffs=[xtr.^7,xtr.^6,xtr.^5,xtr.^4,xtr.^3,xtr.^2,xtr]\(y-y0)
acoeffs=[xtr.^7,xtr.^6,xtr.^5,xtr.^4,xtr.^3,xtr.^2,xtr]\(y-y0);
will give you a polynomial that passes through (x0,y0), but will have a constant term - thus will no longer be of the form you used earlier.
Thus the property of passing through (x0,y0) is payed by losing the property of passing through (0,0).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by