% Author: Ben Nuttall 2009 // www.bennuttall.com % Program: pi.m - A program which generates the decimal places of Pi and % shows them converging one-by-one % More information about the program can be read at % http://www.bennuttall.com/code/2009/11/computing-decimal-places-of.html clear clc p = 0; % Start at 0 for i = 0:1000000000000 % the number of times the program runs - the more iterations, the more accurate Pi gets! p = p + (4*((-1)^i))/(2*i + 1); % The Leibniz formula for pi: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi fprintf('%i Iterations: Pi is approximately equal to %1.16f...\n',i,p) % Printed generation on each iteration end