%compares Newton's method for computing log(2) (log = ln)
%vs the Taylor series method using log(2) = 1+log(2/e) = 1+log(1+(2/e-1))

format long;

f = @(x) exp(x)-2;
f_p = @(x) exp(x);    %f_p = f'

n = 10;     %number of iterations
x = 1;      %initial guess

for i=1:n
    x = x - f(x)/f_p(x);
end

disp('Newton estimate of ln(2) is...')
x

y = 1;
for i=1:n
    y = y+(-1)^(i-1)*(2/exp(1)-1)^i/i;
end

disp('Taylor series estimate of ln(2) is...')
y

disp('True value is...')
log(2)