Skip to content

Monte Carlo simulation method to approximate the area under a curve for continuous fuctions.

Notifications You must be signed in to change notification settings

topollonaketsana/Monte-Carlo-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monte Carlo simulation method to approximate areas for continuous functions

Monte Carlo Simulation

This project demonstrates the Monte Carlo simulation method to approximate the area under the curve for any continuous functions as well the estimation of value Pi using random walks. The computer simulation involves randomly throwing "stones" within a defined boundary and counting how many fall under the curve to estimate the area.

Simulation 1: Area under a curve defined by f(x)

Simulation Description

The Monte Carlo method is a statistical technique that uses random sampling to obtain numerical results. In this simulation 1, we use the Monte Carlo method to approximate the area under the curve of the function ( f(x) = x**3 ) between (x = 0 and x = 3).

Whats needed

Before running the code, ensure you have the following installed:

  • Python 3.x (You can download python here if you dont have it yet)
  • matplotlib library for plotting
  • numpy library for numerical operations

You can install the required libraries using pip:

pip install matplotlib numpy

Usage

  1. Clone the repository and Go to the Project directory:
git clone https://github.com/topollonaketsana/Monte-Carlo-Simulation.git
cd Monte-Carlo-Simulation
  1. Run the Python script:
python monte_carlo_simulation.py

  1. Description of the Python Script: The script monte_carlo_simulation.py performs the following steps:

    • Defines the bounds of the rectangular boundary [x_min, x_max]*[y_min, y_max].
    • Randomly generates points within the boundary [x, y].
    • Checks whether each point lies below the curve y = x**3
    • Calculates the estimated area under the curve based on the ratio of points below (Incount) the curve to the total number of points(N)

Code

The code is already included in the python src file, you can just copy it directly and paste it into your machine for interpretation. Code can be edited for better understanding, eg, on line (8) I included the rate for incount (number of stones thrown inside) this can be edited depending on how you want to interpret the results and how random stones are thrown inside the boundary. Note that N (total number of stones thrown) can be adjusted depending on how many stones you want to throw.


Simulation 2: Estimation of Pi value

Simulation described

//////////////////////

Acknowledgments

About

Monte Carlo simulation method to approximate the area under a curve for continuous fuctions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages