% Example 2_2: Convergence of inner and outer areas.

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

% Initialize n, innerA, and outerA
n= 3;
innerA= 3*sqrt(3)/4;
outerA= 3*sqrt(3);
tol= 0.01;  % convergence tolerance

% Compute and print areas until convergence
while (outerA - innerA > tol)
    fprintf('%4d %9.6f %9.6f \n', n, innerA, outerA);
    n= n+1;
    innerA = (n/2)*sin(2*pi/n);
    outerA = n*sin(pi/n)/cos(pi/n);
end

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