%uses interpolation to find root r=2 of f(x) = 2^x-4
%by interpolating f^(-1) and then evaluating f^(-1)(0)

f = @(x) 2^x-4;
x = linspace(1,3,6)    %6 points equally spaced between 1 and 3

for i=1:n
    y(i) = f(x(i));    %y values for these points
end

for j=2:n              %note x's and y's here are switched
    for i=n:-1:j
        x(i) = (x(i)-x(i-1))/(y(i)-y(i-j+1));
    end
end

r = x(1);
p = 1;
for i=2:n
    p = p*(0-y(i-1));
    r = r+x(i)*p;
end

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