% ATAN4PI  Computes partial sums of the Maclaurin series for
%   arctan(x), at x=1, until we are close to the value of pi.

format long g
x = 1.0;
y = 0;
for i = 1:9999                  % goes well past where needed
  y = y + (-1)^(i+1) * x^(2*i-1) / (2*i-1);   %  y = P_n(1)  when i=n
  err_vs_pi = abs(4 * y - pi);  % distance between  4P_n(1)  and  pi
  [i 4*y err_vs_pi]             % show intermediate results
  if err_vs_pi < 1.0e-3
    break                       % break out of loop if  4P_n(1)  is
  end                           %   close to  pi
end

