% sum over a series to calculate pi.

tic;

n = 500000;
total = 0.0;

for id =1:4:n
    tmp = 1.0/double(id);
    total = total + tmp;
end

for id =3:4:n
    tmp = -1.0/double(id);
    total = total + tmp;
end

  total = 4.0 * total;
  fprintf('%15.12f', total);

toc;

