Python uses triangular iterative method to calculate Pi Pi

Source: Internet
Author: User
Tags cos sin
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.