estimate pi using random numbers

pi is an irrational number and it has infinite decimal places

we will use the concept of probability and definition of pi to calculate the value of pi

estimate pi using random numbers

steps to do so

make a unit circle enclosed within square touching its boundaries

make a unit circle enclosed within square touching its boundaries

randomly plot points inside the square

randomly plot points inside the square

count the number of points that lie inside the circle and total number of points

count the number of points that lie inside the circle and total number of points

calculation of Pi

how probability works

since we are randomly plotting points inside the square, the probability of it lying inside the circle is

area of circle / area of square

how does counting help

how does counting help

since we are plotting many points, empirical probability says that

P = number of points inside circle / Total number of points

using this to find Pi

since we know the empirical probability we will use it to find value of pi

ie. n/N = Pi/4

Pi = 4(number of points inside circle / Total number of points)

conclusion

this is also know as Monte Carlo method, this works perfectly when number of pounts is fairly high

sources

SDE skills

Stealthcopter

stealthcopter

stackoverflow

stackoverflow

geeks for geeks

geeks for geeks