python使用三角迭代计算圆周率PI的代码

把做工程过程较好的内容段做个记录,如下内容段是关于python使用三角迭代计算圆周率PI的内容,应该对码农有一些用。

# Calculating PI using trigonometric iterations
# FB36 - 20130825
import math

x = 1.0
y = 1.0
z = 1.0
w = 1.0
v = 1.0
u = 1.0

for i in range(30):

    x = math.sin(x) + x
    y = math.cos(y) + y
    z = math.cos(z) + math.sin(z) + z
    w = math.cos(w) - math.sin(w) + w
    u =  math.cos(u) / math.sin(u) + u
    
    print i
    print


                                
                        
                                
方法2
                                
                        
                                

# Calculating PI using trigonometric iterations
# FB36 - 20130901
import math

def sin2(x):

def cos2(x):

x = 1.0
y = 1.0
x2 = 1.0
y2 = 1.0

for i in range(5):

    x = math.sin(x) + x
    y = math.cos(y) + y
    x2 = sin2(x2) + x2
    y2 = cos2(y2) + y2

猜你喜欢

转载自blog.csdn.net/weixin_44409623/article/details/89045712