Newton interpolation for 9 values

1 次查看(过去 30 天)
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
Because the time step is not constant, you should use divided difference not differences
Evangelos Rompogiannakis
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