Python uses trigonometric iterations to calculate Pi pi _python

Source: Internet
Author: User
Tags cos sin

The example in this article describes Python's method of calculating pi pi using trigonometric iterations. Share to everyone for your reference. Specifically as follows:

Method 1:

Copy Code code 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:

Copy Code code 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

I hope this article will help you with your 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.