The example in this paper describes how Python uses triangular iterations to calculate Pi Pi. Share to everyone for your reference. Specific as follows:
Method 1:
The code is as follows:
# 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
v = math.cos (v) * Math.sin (v) + V
U = Math.Cos (u)/Math.sin (U) + u
Print I
Print x, y * 2.0, Z * 4.0/3.0, W * 4.0, V * 2.0, U * 2.0
Print
Method 2:
The code is as follows:
# Calculating PI Using trigonometric iterations
# fb36-20130901
Import Math
def sin2 (x):
Return ((MATH.E * * Complex (0.0, x)-MATH.E * * Complex (0.0, x))/2.0). imag
def cos2 (x):
Return ((MATH.E * * Complex (0.0, x) + MATH.E * * Complex (0.0, x))/2.0). Real
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
Print I, x, x2, y * 2.0, y2 * 2.0
Hopefully this article will help you with Python programming.