- Get link
- X
- Other Apps
This method is based on generating random values for parameters or inputs to explore the behaviour of complex systems, now this method is used in various domains like: Engineering, science and finance. These approaches tend to follow a particular pattern:
1- Define a domain of possible inputs.
2- Generate inputs randomly from the domain using a certain specified probability distribution.
3- Perform a deterministic computation using the inputs.
4- Aggregate the results of the individual computations into the final result.
Here is an example of using Monte Carlo simulation to approximate the value of Pi:
In this case we have 2 parameters x,y which defines a location in the plane (e.g The picture on the left).
We will calculate the probability to have a point in the 1/4 Circle area, with a radius of 1.
To calculate Pi we are going to use a C# application that will follow these steps:
- Define the number of samples (n)
- Generate n samples for x,y
- Get the number of samples that define a point in the 1/4 Circle, you can use this formula: x^2 * y^2 =<>
- Calculate the probability of having a point in this area (p=Pi/4)
- Calculate Pi = p * 4
Here is the C# code:
Comments
Post a Comment