<texit info> author=Roman Putanowicz title=Solution to exercise 5.1.3 </texit>
<sxh c> R = input(“Give R : ”);
function p = polyarea(R,n)
p = n * 1/2 * R^2 * sin(2*pi/n);
endfunction
epsilon = 0.005; trueArea = pi*R^2;
n = 2; do
n = n+1; pa = polyarea(R,n); relError = abs((pa-trueArea)/trueArea);
until relError < epsilon; printf(“For n=%d the relative error is %g\n”, n, relError); </sxh>
<texit> \begin{lstlisting} R = input(“Give R : ”);
function p = polyarea(R,n)
p = n * 1/2 * R^2 * sin(2*pi/n);
endfunction
epsilon = 0.005; trueArea = pi*R^2;
n = 2; do
n = n+1; pa = polyarea(R,n); relError = abs((pa-trueArea)/trueArea);
until relError < epsilon; printf(“For n=%d the relative error is %g\n”, n, relError); \end{lstlisting} </texit>