Escolar Documentos
Profissional Documentos
Cultura Documentos
Again, note that the only change is that the indices in this line have all been increased by
one. The loops are still:
for i = 1:n
for j = 1:i
There is a better way to write Algorithm 3.1. Namely, to compute each new column of the
Neville's algorithm table, so that the program doesn't have to store away the whole table as a
matrix, but rather just a vector which is a column. This is what the code below does. There
is a disadvantage--the program can not be modified to add nodes as needed, as suggested on
page 119. It should be saved as "nev.m":
function y = nev(xx,n,x,Q)
% Neville's algorithm as a function (save as "nev.m")
%
% inputs:
%
n = order of interpolation (n+1 = # of points)
%
x(1),...,x(n+1)
x coords
%
Q(1),...,Q(n+1)
y coords
%
xx=evaluation point for interpolating polynomial p
%
% output: p(xx)
for i = n:-1:1
for j = 1:i
Q(j) = (xx-x(j))*Q(j+1) - (xx-x(j+n+1-i))*Q(j);
Q(j) = Q(j)/(x(j+n+1-i)-x(j));
end
end
y = Q(1);
1950
1960
1970
1980
1990
132165
151326
179323
203302
226542
249633
But to actually plot out some polynomials, as in problem II. on assignment #2, you probably
want to actually write a new program, for instance:
% save in something like "probII.m"
%
--the name doesn't matter since it's not a function
% plot out the n=2, 4, 8, 16 polynomials which interpolate the
%
function f(x) = 1/(1+25x^2) on the interval [-1,1] using
%
equally spaced points
xx=[-1:.01:1];