%section 4.1 computer problem #9

n = 4;
x = [0,5,10,15];
y = [1.792,1.519,1.308,1.140];  %we think of y=f(x) where f is unknown

for j=2:n              %note x's and y's here are switched
    for i=n:-1:j       %this is because we are interpolating f^(-1)
        x(i) = (x(i)-x(i-1))/(y(i)-y(i-j+1));
    end
end

%after the above loop, x = coefficients of the interpolant P of f^(-1)

r = x(1);
p = 1;
for i=2:n              %here we evaluate P(0) ~= f^(-1)(0) = root of f
    p = p*(0-y(i-1));
    r = r+x(i)*p;
end

disp('estimate of root is...')
r
