Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. noOfTrials = 500;
  2. points = RandomPoint[Sphere[], {noOfTrials, 2}];
  3. (*gives the length of a line from pt1 to pt2 that lies inside a
  4. sphere at origin of radius r*)
  5. dFunc[pt1_, pt2_, r_] := Module[
  6. {midPt, h},
  7. midPt = (pt1 + pt2)*0.5;
  8. h = Norm[midPt];
  9. If[h >= r, 0, 2 N@Sqrt[r^2 - h^2]]
  10. ]
  11. (*simulation*)
  12. sim = Module[
  13. {dr, l, dlTotal},
  14. dr = 10^-2;
  15. Table[
  16. dlTotal =
  17. Plus @@ Table[(dFunc[#1, #2, r + dr] - dFunc[#1, #2, r]) & @@
  18. pair, {pair, points}];
  19. {r, dlTotal/(4 Pi r^2 dr)}
  20. , {r, 0.01, 1, dr}
  21. ]
  22. ];
  23. (*plot*)
  24. ListPlot[sim]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement