SHARE
TWEET

Pentru prostu' satului.

a guest May 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top