% 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 entirely with array notation. To see exactly what
%       each of the operators .^ .* ./ is doing please put the following in the
%       command prompt: 
%
%           help ops
%
%       This gives a list of all the operators in Matlab and then do help
%       operator_name to see what the operator is doing. For example help power
%       will tell you that .^ takes the power of each element in a matrix.
%       Then you can convince yourself that the array fs contains all the terms
%       in the sum.
%
%       For more details on the derivation of this Taylor expansion
%       please see the class notes
function err = logtaylor2(x,n)
ks=1:n;
fs = (-1).^(ks-1).*(x.^ks./ks);
f = sum(fs);
err=abs(f-log(1+x));
