This project demonstrates the use of the Monte Carlo Simulation technique to estimate the value of Pi. By generating random points within a unit square and determining how many fall inside a unit circle, the algorithm leverages the principles of probability to estimate Pi.
This simulation is a great example of how computational methods can approximate complex mathematical constants in a simple yet effective manner.
- Multilingual Support: Includes implementations in Python, MATLAB, R, C#, Julia, and more.
- Easy-to-understand: Clear and well-documented code that is accessible for both beginners and experienced developers.
- Practical Use Case: A great way to understand the principles of Monte Carlo simulations and probability estimation.
- Optimized for Performance: Implements efficient methods for random point generation and calculation of the proportion that lies inside the circle.
The algorithm estimates Pi by randomly generating a large number of points within a unit square (with coordinates ranging from 0 to 1). The number of points that fall within the unit circle (radius = 1) is counted, and the ratio of points inside the circle to the total points generated is used to estimate Pi using the formula: The larger the number of points, the more accurate the estimation becomes.
This project contains implementations in the following languages:
- Python
- MATLAB
- R
- C#
- Julia
Each implementation is self-contained and demonstrates the same Monte Carlo Pi estimation method in its respective language.
To run the Python version of the simulation:
- Clone this repository:
git clone https://github.com/SudeErzurumlu/Monte-Carlo-Simulation-for-Estimating-Pi
- Navigate to the Python folder:
cd python
- Run the script:
python monte_carlo_pi.py
To run the MATLAB version, open monte_carlo_pi.m
and execute it within the MATLAB environment.
For R, run the monte_carlo_pi.R
script after installing the necessary libraries.
For the C# implementation, compile and execute the MonteCarloPiEstimation.cs
file.
Run the monte_carlo_pi.jl
script within the Julia environment.
Feel free to fork the repository and submit pull requests to improve or extend the functionality. Contributions are always welcome.
This project is licensed under the MIT License.
For any questions or suggestions, feel free to open an issue on this repository.