编写一个函数,通过计算公式pi=arctan(1/5)-arctan(1/239),返回pi的近似值,其中arctan是数学库中的切线函数。Im使用Python3.4.1
我使用的功能是:
def wallis(pairs):
acc = 1
num = 2
for apair in range(pairs):
leftterm = math.atan(0.2)
rightterm = math.atan(0.0041)
acc = leftterm - rightterm
return pi
但没用。令人困惑。
Tags:
我不知道你从哪里得到的公式
看起来你在尝试做Wallis公式,
pi = (2/1) * (2/3) * (4/3) * (4/5) * ...
,然后把中流转换成Machin公式,pi == 16 * atan(1/5) - 4 * atan(1/239)
。那么
相关问题 更多 >
编程相关推荐