Skip to content

dvjn/CalcuPi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculate Pi using Monte Carlo method

Please ⭐ if you like it!

Explanation πŸ€”

Steps 🎲

  • Use a square of arbitrary side length and inscribe a circle inside it.
  • Put random points on the square using a uniform distribution.
  • Count the number of random points falling inside the circle.
  • Calculate the approximate value of pi using,
    4 * points inside the circle / total number of points.

Maths πŸ“

Why 4 * points inside the circle / total number of points?

Let's consider,
Radius of circle, r
Side of square, 2r
Number of points inside the circle, C
Total number of points, S

Thus,
Area of circle = Ο€rΒ²
Area of square = 4rΒ²

For large enough number of random points, we can consider that the ratio of areas of circle to square is equal to the ratio of points inside the circle to the total number of points, ie, Ο€rΒ²/4rΒ² = C/S.
Which can be simplified to, Ο€ = 4*C/S

Links ✨

About

Calculate Pi using Monte Carlo method

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published