% Convergence of inner and outer areas of
% regular n-gons on unit circle

% Print the column headings
fprintf('\n n\t A(n)\t B(n)\n')
fprintf('---------------------------\n')

% The triangle case
n= 3; % Number of polygon edges
A_n= (n/2)*sin(2*pi/n); % Inscribed aread
B_n= n*tan(pi/n); % Circumscribed Area
delta= 0.01; % Error tolerance

% Compute and print areas until convergence
while (B_n - A_n > delta)
fprintf('%4d %9.6f %9.6f \n', n, A_n, B_n)
n= n+1;
A_n = (n/2)*sin(2*pi/n);
B_n = n*tan(pi/n);
end
fprintf('%4d %9.6f %9.6f \n', n, A_n, B_n)

fprintf('---------------------------\n')