% Script areaCircle
% Convergence of polygons to unit circle by area.

% Print the column headings
fprintf('\n n\t inner n-gon outer n-gon\n');
fprintf('-----------------------------\n');

n= 3;
innerA= (n/2)*sin(2*pi/n); % area of inscribed n-gon
outerA= n*sin(pi/n)/cos(pi/n); % area of circumscribed n-gon
tol= 0.01; % convergence tolerance

% Compute and print areas until convergence
while outerA - innerA > tol
if rem(n,5)==0 % display output for n=5,10,15,...
fprintf('%4d %10.6f %12.6f \n', n, innerA, outerA);
end
n= n+1;
innerA = (n/2)*sin(2*pi/n);
outerA = n*sin(pi/n)/cos(pi/n);
end
fprintf('%4d %10.6f %12.6f \n', n, innerA, outerA);

fprintf('-----------------------------\n');
fprintf('A %d-sided polygon is almost a circle!\n', n)
fprintf('(Area convergence tolerance: %f)\n', tol)