蒙特卡洛方法计算pi值

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

计算机模拟常常需要用到随机选择的数。本文从随机数的一个简单应用开始简要地介绍Python的random模块。

 使用蒙特卡洛方法计算pi值

 Links:该问题来自于pudure university(普渡大学)python课程中的problem set2

Monte Carlo methods are used to simulate complex physical and mathematical systems by repeated random sampling. In simple terms, given a probability, p, that an event will occur in certain conditions, a program generates those conditions repeatedly. The number of times the event occurs divided by the number of times the conditions are generated should be approximately equal to p.

蒙特卡洛方法通过重复随机取样用于复杂的物理和数学系统的仿真。简单地说,给定一个变量p,用于描述事件在一定条件下发生的概率,程序重复地生成这些条件。事件发生的次数除以总产生次数应该近似地等于概率p。

The Monte Carlo method can be used to generate an approximate value of pi. The figure below shows a unit square with a quarter of a circle inscribed. The area of the square is 1 and the area of the quarter circle is pi/4. Using a random number generator, imagine “throwing” random points at the square. The ratio between the number of points that fall inside the circle (red points) and the total number of points thrown (red and green points) gives an approximation to the value of pi/4. This process is a Monte Carlo simulation approximating pi.

蒙特卡洛方法可以用于产生接近pi的近似值。下图显示了一个带有1/4圆在内的正方形单元、落在圈内(红点)的点和总的投在正方形(红和绿点)上的点的比率给出了pi/4的近似值。这一过程称为使用蒙特卡洛方法来仿真逼近pi实际值。

 

蒙特卡洛方法计算pi值_第1张图片

主要是思想!

转载于:https://my.oschina.net/hanzhankang/blog/203792

你可能感兴趣的:(蒙特卡洛方法计算pi值)