Advertisement
Guest User

Untitled

a guest
May 24th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.36 KB | None | 0 0
  1. function shit = ellipseMC
  2.  
  3. f1 = @(x,y) x.^2/16 + y.^2 - 1;
  4. fimplicit(f1)
  5. hold on
  6.  
  7. Xrand = 8.*rand(10000,1) -4;
  8. Yrand = 2.*rand(10000,1) -1;
  9.  
  10. Nin = 0;
  11. Nout = 0;
  12.  
  13. plot(Xrand,Yrand,'.');
  14.  
  15. for ii = 1:10000
  16.     if ((Xrand(ii)^2/16 + Yrand(ii)^2 <= 1))
  17.         Nin = Nin + 1;
  18.     else
  19.         Nout = Nout + 1;
  20.     end
  21. end
  22.  
  23. disp(Nin/Nout);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement