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
2020 年 12 月 4 日
Because the time step is not constant, you should use divided difference not differences
回答 (1 件)
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:
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!