% nStars
% The table problem..
clc
disp('   n          A(n)               A(n+1)           A(n)/pi    A(n+1/pi)')
disp('--------------------------------------------------------------------')
for k=1:20
    n = 10*k;
    %n is even...
    theta = pi/n;
    A_n = n*sin((n-2)*theta)*sin(theta)/(sin(theta)+sin((n-3)*theta));
    m = n+1;
    % m is odd...
    theta = pi/m;
    A_nplus1 = m*sin((m-1)*theta)*sin(theta)/(sin(theta) + sin((m-2)*theta));
    fprintf('%4d  %18.15f  %18.15f        %5.3f     %5.3f\n',n,A_n,A_nplus1,A_n/pi,A_nplus1/pi)
end

% The smallest n problem..

% The 3-star...
n = 3;
theta = pi/n;
A_n = n*sin((n-1)*theta)*sin(theta)/(sin(theta)+sin((n-2)*theta));
% The 5 -star
n_next = n+2;
theta_next = pi/n_next;
A_next = n_next*sin((n_next-1)*theta_next)*sin(theta_next)/...
                            (sin(theta_next)+sin((n_next-2)*theta_next));
% keep iterating as long as A_n and Anext are sufficiently different..                      
while abs(A_n - A_next) >.0001
    n = n+2;
    A_n = A_next;
    % Compute the area of the "next" n-star. Use the odd-n formula
    n_next = n+2;
    theta_next = pi/n_next;
    A_next = n_next*sin((n_next-1)*theta_next)*sin(theta_next)/...
                             (sin(theta_next)+sin((n_next-2)*theta_next));  
end
fprintf('\n\n\nn_odd = %1d\n\n',n)