【发布时间】:2009-06-11 17:10:29
【问题描述】:
我已经尝试了许多算法来使用蒙特卡洛找到 π。 解决方案之一(在 Python 中)是这样的:
def calc_PI():
n_points = 1000000
hits = 0
for i in range(1, n_points):
x, y = uniform(0.0, 1.0), uniform(0.0, 1.0)
if (x**2 + y**2) <= 1.0:
hits += 1
print "Calc2: PI result", 4.0 * float(hits) / n_points
可悲的是,即使是 1000000000,精度也非常差(3.141...)。
这是此方法可以提供的最大精度吗? 我选择蒙特卡洛的原因是它很容易在平行部分中分解。 有没有另一种易于分解计算的 π 算法?
【问题讨论】:
标签: python statistics montecarlo pi