<texit info> author=Roman Putanowicz title=Solution to exercise 5.1.3 </texit>

back

Solution to exercise 5.1.3

<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>

  • en/teaching/subjects/it/labs/sol_5_1_3.txt
  • Last modified: 2017/10/02 15:54
  • (external edit)