% Compute error in approximation of log(1+x) by Taylor expansion at
% x=0 with n terms
%
% Inputs
% x where the approximation is made
% n number of terms in the approximation
%
% Outputs
% err approximation error (in absolute value)
%
% Note: this is implemented with a simple for loop
% for more details on the derivation of this Taylor expansion
% please see the class notes
function err = logtaylor1(x,n)
f = 0;
for k=1:n,
f = f + (-1)^(k-1)*x^k/k;
end;
err=abs(f-log(1+x));