Polynomial Approximation, is it possible in matlab?

조회 수: 11 (최근 30일)
Milky Way
Milky Way 2019년 1월 3일
댓글: Luna 2019년 1월 4일
I have four points on the graph with the following coordinates.
x1 - 1
y1 - 3.5
x2 - 2
y2 - 14/3
x3 - 3
y3 - 14
x4 - 4
y4 - 28
Is it possible using the Lagrange approximation polynomial coefficient calculation method to find the polynomial / function given by the four points?
I don't know the algorithm very well and I don't have the strongest matlab knowledge. I'm learning.
Thank you.
MATLAB Version: 8.5.0.197613 (R2015a)

답변 (1개)

Luna
Luna 2019년 1월 3일
편집: Luna 2019년 1월 3일
Hi,
Try below (it uses least squares):
For lagrange you can look at that link:
x1 = 1;
y1 = 3.5;
x2 = 2;
y2 = 14/3;
x3 = 3;
y3 = 14;
x4 = 4;
y4 = 28;
x1Array = [x1,x2,x3,x4];
y1Array = [y1,y2,y3,y4];
n = 1; % polynomial degree (you can change it as you wish)
p = polyfit(x1Array,y1Array,n); % p is coefficient of your polynomial: P(X) = P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1) descending order.
newY = polyval(p,x1Array); % function results
plot(x1Array,y1Array, 'bo',x1Array,newY,'-r');
grid;
legend('Data','Fitted Data');
  댓글 수: 11
Torsten
Torsten 2019년 1월 4일
But you know that using the interpolating spline method to calculate the coefficients is not what you are supposed to do in your homework (it says something about "Lagrange interpolation polynomial", doesn't it) ??
Luna
Luna 2019년 1월 4일
Yes, it says lagrange that's why I gave the lagrangepoly link from fileexchange in my answer.
Please check the file and use. It does the same thing with only Lagrange method.
It also explains with examples.

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

카테고리

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

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by