Pi Calculations

Configuration


Iteration per Cycle: Cycles:

PI Calc

Total Iteration: - Inside: - Outside: - Pi Calc: 0.0000000 - Error: 0.00000%

Inside Outside Pi Calc Pi Error Pi Calc Acum Pi Error Acum

Simple method to calculate Pi using Montecarlo simulation

The method used square with a inside circle. The x-Axis and y-Axis goes from -1 to 1 and the radio for the inside circle is 1.

In order to approach this method you can formulate the questions what is the probability of a any random number for a pair (x,y) will be inside the circle?. Let’s define P as this probability

Lest’s calculate the area of a square, and a circle inside the square. We can asume the cicle radio is r, and the side of the square is 2r

So, the Probability can be calculated as

The calculated

The Montecarlo approach. In order to apply this method using the Montecarlo simulation, we need to have a set of point (x,y) and we need to calculate the aproximation for the probability. This probabilty P is obtained dividing the cases inside the circle by the total of iteration. Remember, our square is -1 to 1, and the circle has a radio r=1. In order to know if a par(x,y) is inside the cicle We need to calculate the distance to the center of the square, the coordenates (0,0). If the distance is less or equal to 1, the point in inside the circle. Using Pythagoras theorem, we calculate the distance D as

Because our radio is equal to 1, we can use the next equation to figure out is the point is inside the cirle

So,

Steps:

  1. Generate a set(x,y) of uniform random number from -1 to 1. This set will identify a position inside the square.
  2. Identify the number of cases that are inside the circle.
  3. Calculate the probabilty of the any set (x,y) will be inside the circle and estimate Pi
An error has occurred. This application may no longer respond until reloaded. Reload 🗙