% Archimedes2 .m
% Compute pi by finding the perimeters of inscribing 
% regular polygons of sides 2^(n+1), n = 1,2, ...
% iteratively for large n.
% This version uses a recursion relation for gn,
% is efficient & has no bad cancellations.
% Note: pi = 3.1415926535897932384626433832795029...
% K. Ming Leung, 01/28/04

clear; 
fprintf('\n');
twoN = 2;  % can be omitted
G(1) = 2;
fprintf('%4i %20.15f\n',1,twoN*sqrt(G(1)));

for n = 1:29
    n1 = n+1;
    G(n1) = G(n)/(2 + sqrt(4-G(n)));
    twoN = twoN*2;                % can be omitted
    %disp([n1 twoN*sqrt(G(n1))]); % can be omitted till after loop
    fprintf('%4i %20.15f\n',n1,twoN*sqrt(G(n1)));
end

%myPi = twoN*sqrt(G(n1))