We now have a youtube channel. Subscribe!

The Python Trigonometric Functions



Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we are going to be discussing about the Trigonometric Functions in Python.

These trigonometric functions where listed out in our tutorial on Python Numbers without being properly explained with examples. So now i will be explaining each of them one after the other.

Python Number acos() Function

The built-in Python number acos() function returns the arc cosine of x, in radians.

Syntax

The following is the syntax for acos() function -

acos(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value in the range of -1 to 1. If x is greater than 1, then it will generate an error.

Return Value

This returns arc cosine of x, in radians.

Example

The following example shows the usage of acos() function -

#!/usr/bin/python
import math

print "acos(0.64) : ",  math.acos(0.64)
print "acos(0) : ",  math.acos(0)
print "acos(-1) : ",  math.acos(-1)
print "acos(1) : ",  math.acos(1)

Output

Below is the output of the above example -

acos(0.64) :  0.876298061168
acos(0) :  1.57079632679
acos(-1) :  3.14159265359
acos(1) :  0.0


Python Number asin() Function

The Python number asin() function returns back the arc sine of x, in radians.

Syntax

The following is the syntax for asin() function -

asin(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value in the range of -1 to 1. If x is greater than 1, then it will generate an error.

Return Value

This returns the arc sine of x, in radians.

Example

The following example shows the usage of asin() function -

#!/usr/bin/python
import math

print "asin(0.64) : ",  math.asin(0.64)
print "asin(0) : ",  math.asin(0)
print "asin(-1) : ",  math.asin(-1)
print "asin(1) : ",  math.asin(1)

Output

Below is the output of the above example -

asin(0.64) :  0.694498265627
asin(0) :  0.0
asin(-1) :  -1.57079632679
asin(1) :  1.57079632679

Python Number atan() Function

The built-in Python number atan() function returns the arc tangent of x, in radians.

Syntax

The following is the syntax for atan() function -

atan(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value.

Return Value

This returns arc tangent of x, in radians.

Example

The following example shows the usage of atan() function -

#!/usr/bin/python
import math

print "atan(0.64) : ",  math.atan(0.64)
print "atan(0) : ",  math.atan(0)
print "atan(10) : ",  math.atan(10)
print "atan(-1) : ",  math.atan(-1)
print "atan(1) : ",  math.atan(1)

Output

Below is the output of the above example -

atan(0.64) :  0.569313191101
atan(0) :  0.0
atan(10) :  1.4711276743
atan(-1) :  -0.785398163397
atan(1) :  0.785398163397

RECOMMENDED POST: Python Pass Statement

Python Number atan2() Function

The built-in Python number atan2() function returns the atan(y / x), in radians.

Syntax

The following is the syntax for atan2() function -

atan2(y, x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • y - This must be a numeric value.
  • x - This must be a numeric value.

Return Value

This returns atan(y / x), in radians.

Example

The following example shows the usage of atan2() function -

#!/usr/bin/python
import math

print "atan2(-0.50,-0.50) : ",  math.atan2(-0.50,-0.50)
print "atan2(0.50,0.50) : ",  math.atan2(0.50,0.50)
print "atan2(5,5) : ",  math.atan2(5,5)
print "atan2(-10,10) : ",  math.atan2(-10,10)
print "atan2(10,20) : ",  math.atan2(10,20)

Output

Below is the output of the above example -

atan2(-0.50,-0.50) :  -2.35619449019
atan2(0.50,0.50) :  0.785398163397
atan2(5,5) :  0.785398163397
atan2(-10,10) :  -0.785398163397
atan2(10,20) :  0.463647609001

Python Number cos() Function

The Python number cos() function returns the cosine of x, in radians.

Syntax

The following is the syntax for cos() function -

cos(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value.

Return Value

This function returns a numeric value between the range of -1 and 1, which represents the cosine of the angle.

Example

The following example shows the usage of cos() function -

#!/usr/bin/python
import math

print "cos(3) : ",  math.cos(3)
print "cos(-3) : ",  math.cos(-3)
print "cos(0) : ",  math.cos(0)
print "cos(math.pi) : ",  math.cos(math.pi)
print "cos(2*math.pi) : ",  math.cos(2*math.pi)

Output

Below is the output of the above example -

cos(3) :  -0.9899924966
cos(-3) :  -0.9899924966
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0


Python Number hypot() Function

The built-in Python number hypot() function returns the Euclidean norm, sqrt(x*x + y*y).

Syntax

The following is the syntax for hypot() function -

hypot(x, y)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value.
  • y - This must be a numeric value.

Return Value

This returns the Euclidean norm, sqrt(x*x + y*y).

Example

The following example shows the usage of hypot() function -

#!/usr/bin/python
import math

print "hypot(3, 2) : ",  math.hypot(3, 2)
print "hypot(-3, 3) : ",  math.hypot(-3, 3)
print "hypot(0, 2) : ",  math.hypot(0, 2)

Output

Below is the output of the above example -

hypot(3, 2) :  3.60555127546
hypot(-3, 3) :  4.24264068712
hypot(0, 2) :  2.0

Python Number sin() Function

The Python number sin() function returns the sine of x, in radians.

Syntax

The following is the syntax for sin() function -

sin(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value.

Return Value

This function returns a numeric value between the range of -1 and 1, which represents the sine of x. 

Example

The following example shows the usage of sin() function -

#!/usr/bin/python
import math

print "sin(3) : ",  math.sin(3)
print "sin(-3) : ",  math.sin(-3)
print "sin(0) : ",  math.sin(0)
print "sin(math.pi) : ",  math.sin(math.pi)
print "sin(math.pi/2) : ",  math.sin(math.pi/2)

Output

Below is the output of the above example -

sin(3) :  0.14112000806
sin(-3) :  -0.14112000806
sin(0) :  0.0
sin(math.pi) :  1.22464679915e-16
sin(math.pi/2) :  1.0


Python Number tan() Function

The built-in Python number tan() function returns the tangent of x, in radians.

Syntax

The following is the syntax for tan() function -

tan(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details

  • x - This must be a numeric value.

Return Value

This function returns a numeric value between the range of -1 and 1, which represents the tangent of x. 

Example

The following example shows the usage of tan() function -

#!/usr/bin/python
import math

print "tan(3) : ",  math.tan(3)
print "tan(-3) : ",  math.tan(-3)
print "tan(0) : ",  math.tan(0)
print "tan(math.pi) : ",  math.tan(math.pi)
print "tan(math.pi/2) : ",  math.tan(math.pi/2)
print "tan(math.pi/4) : ",  math.tan(math.pi/4)

Output

Below is the output of the above example -

tan(3) :  -0.142546543074
tan(-3) :  0.142546543074
tan(0) :  0.0
tan(math.pi) :  -1.22460635382e-16
tan(math.pi/2) :  1.63317787284e+16
tan(math.pi/4) :  1.0

Python Number degrees() Function
Python number degrees() function converts angle x from radians to degrees.

Syntax
The following below is the syntax for degrees() function -

degrees(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details
  • x - This must be a numeric value.

Return Value
This returns degrees value of an angle.

Example
The following example shows the usage of degrees() function -

#!/usr/bin/python
import math

print "degrees(3) : ",  math.degrees(3)
print "degrees(-3) : ",  math.degrees(-3)
print "degrees(0) : ",  math.degrees(0)
print "degrees(math.pi) : ",  math.degrees(math.pi)
print "degrees(math.pi/2) : ",  math.degrees(math.pi/2)
print "degrees(math.pi/4) : ",  math.degrees(math.pi/4)

Output
Below is the output of the above example -

degrees(3) :  171.887338539
degrees(-3) :  -171.887338539
degrees(0) :  0.0
degrees(math.pi) :  180.0
degrees(math.pi/2) :  90.0
degrees(math.pi/4) :  45.0

RECOMMENDED POST: Python Basic Syntax 

Python Number radians() Function
Python number radians() function converts angle x from degrees to radians.

Syntax
The following below is the syntax for radians() function -

radians(x)

Note - This function is not directly accessible, so we need to import the math module and then we need to call this function using the math static object.

Parameter Details
  • x - This must be a numeric value.

Return Value
This returns radians value of an angle.

Example
The following example shows the usage of radians() function -

#!/usr/bin/python
import math

print "radians(3) : ",  math.radians(3)
print "radians(-3) : ",  math.radians(-3)
print "radians(0) : ",  math.radians(0)
print "radians(math.pi) : ",  math.radians(math.pi)
print "radians(math.pi/2) : ",  math.radians(math.pi/2)
print "radians(math.pi/4) : ",  math.radians(math.pi/4)

Output
Below is the output of the above example -

radians(3) :  0.0523598775598
radians(-3) :  -0.0523598775598
radians(0) :  0.0
radians(math.pi) :  0.0548311355616
radians(math.pi/2) :  0.0274155677808
radians(math.pi/4) :  0.0137077838904

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be studying about Python Strings.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain