Languages
[Edit]
EN

JavaScript - how to use Monte Carlo method to calculate pi constant number?

6 points
Created by:
Kia-H
546

Using JavaScript it is possible to calculate surface area (definite integral) in the following way.

1. Circle surface area calculation example

Edit

Main idea of this method is to:

  1. random big amount of points
  2. check all time if every next one point is inside a circle or not,
  3. compute coefficient by dividing number of points inside of circle by outside one point
  4. multiply the coefficient by square surface area - this way from proportion it is possible to get approximated circle surface area,
  5. use transformed circle surface area formula to calculate PI number.

Note: the longer the simulation is performed, the results are more precised.

References

Edit
  1. Monte Carlo method - Wikipedia
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - math (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join