Newton interpolation for 9 values

조회 수: 1 (최근 30일)
Evangelos Rompogiannakis
Evangelos Rompogiannakis 2020년 12월 4일
답변: Monisha Nalluru 2020년 12월 7일
Hello im trying to run an interpolation for the values shown below in the code but for a reason when i plot the results I get a curve that doesnt go through all the points. Can someone help me solve this problem plz?
X=[0 14 36 52 68 75 83 94 100]; % time (sec)
Y=[6000 5750 4530 3675 1762 1279 895 429 151]; % Range (meters)
n = length(X) % set n = 9
h = X(2)-X(1); % stepsize
d = zeros(n,n) % 9x9 matrix of zeros
d(:,1)= Y %
for j = 2:n
for i=j:n
d(i,j) = d(i,j-1)-d(i-1,j-1)
end
end
C = d(n,n);
for k = n-1:-1:1
p = poly(X(1))/h;
p(2) = p(2)-(k-1);
C = conv(C,p)/k;
m = length(C);
C(m) = C(m)+d(k,k);
end
A = polyval(C,n)
t = linspace(X(1),X(n),100)
y = polyval(C,t)
set(figure(1),'DefaultLineLineWidth',1.5)
plot(t,y,'b')
hold on
plot(X,Y,'ro')
Thank you !
  댓글 수: 2
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 12월 4일
Because the time step is not constant, you should use divided difference not differences
Evangelos Rompogiannakis
Evangelos Rompogiannakis 2020년 12월 4일
Could you please give a hint on how to implement this in my code. I used the difference of X(1) and X(2).

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

답변 (1개)

Monisha Nalluru
Monisha Nalluru 2020년 12월 7일
Inorder to use divided difference in newton interpolation in the code
Refer the the corresponding x according to formula
As an example
for j = 2:n
for i=j:n
d(i,j) = (d(i,j-1)-d(i-1,j-1))/(X(i)-X(i-j+1));
end
end
Also refer the code from file example which can give you idea on iimplementation:

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by