(3.1) Neville interpolation: MatLab code + download link.

preview_player
Показать описание
Code's download link:

Alternatively, you can copy and paste from below:

% Neville's iterated interpolation algorithm
% Find the approximate value of f(1.5) from
% (x,y)= (0,1), (1,e), (2,e^2) & (3,e^3).

n = input('Enter n for (n+1) nodes, n: ');
xx = zeros(1,n+1);
q = zeros(n+1,n+1);

for i = 0:n
fprintf('Enter x(%d) and f(x(%d)) on separate lines: \n', i, i);
xx(i+1) = input(' ');
q(i+1,1) = input(' ');
end
x = input('Now enter a point at which to evaluate the polynomial, x = ');

d = zeros(1,n+1);
d(1) = x-xx(1);
for i = 1:n
d(i+1) = x-xx(i+1);
for j = 1:i
q(i+1,j+1) = (d(i+1)*q(i,j)-d(i-j+1)*q(i+1,j))/(d(i+1)-d(i-j+1));
end
end

fprintf('Table for interpolation evaluated at x = %11.8f: \n', x);
for i = 0:n
fprintf('%11.8f ', xx(i+1));
for j = 0:i
fprintf('%11.8f ', q(i+1,j+1));
end
fprintf('\n');
end
Рекомендации по теме
Комментарии
Автор

Thank you for the explanation and the code. Very helpful

ganeshalapenanggaputra