Advertisement
Guest User

Pentru prostu' satului.

a guest
May 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. ```{r}
  2. #C1
  3. parabArea = function(N){
  4.   counter = 0;
  5.  
  6.   a = 2;
  7.  
  8.   for (i in 1:N){
  9.     u = runif(1, -sqrt(a), sqrt(a))
  10.     v = runif(1, -sqrt(a), sqrt(a))
  11.     w = runif(1, -a, a)
  12.    
  13.     realW = u*u + v*v;
  14.    
  15.     if (w > realW){
  16.       counter = counter + 1;
  17.     }
  18.   }
  19.  
  20.   areaCuboid = (2*sqrt(a))**2 * 2*a
  21.  
  22.   areaParab = areaCuboid*counter/N;
  23.   realArea = pi*a*a/2;
  24.  
  25.   absoluteError = abs(areaParab-realArea);
  26.   relativeError = abs(areaParab-realArea) / abs(realArea);
  27.  
  28.   print("\n");
  29.   print(absoluteError);
  30.   print(relativeError);
  31.  
  32.  
  33.   return (areaParab);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement