% File: cpi_serial.m
% Purpose: Serial computation of pi in Matlab with 
%          measurement of the time taken to complete the computation.

n = 4800000;
sum = 0.0;

sp = 1;
ep = n;

tic;  % start a timer for the pi computation
h = 1.0 / n;
for i = sp : ep 
  x = h * (i-0.5);
  sum = sum + 4.0/(1.0+x*x);
end
pi = h * sum;
toc;  % print the elapsed time since tic was used 

fprintf('pi: %.16f\n', pi);
