Change language

Math Functions in Python | Set 3 (trigonometric and angle functions)

|

Math functions in Python | Set 2 (logarithmic and power functions)

Trigonometric and angle functions are discussed in this article.

1. sin () : — This function returns the sine of the value passed as an argument. The value passed to this function must be in radians .

2. cos () : — This function returns the cosine of the value passed as an argument. The value passed to this function must be in radians .

# Python code to demonstrate how it works
# sin () and cos ()

 
# import math for math operations

import math

 

a = math.pi / 6

 
# returns sine pi / 6

print ( "The value of sine of pi / 6 is:" , end = "")

print (math.sin (a))

 
# returns cosine pi / 6 value

print ( "The value of cosine of pi / 6 is:" , end = "")

print (math.cos (a))

Output:

 The value of sine of pi / 6 is: 0.49999999999999994 The value of cosine of pi / 6 is: 0.8660254037844387 

3. tan () : — This function returns the tangent of the value passed as an argument. The value passed to this function must be in radians .

4. hypot (a, b) : — returns the hypotenuse of the values ​​passed in the arguments. Returns numerically sqrt (a * a + b * b) .

# Python code to demonstrate how it works
# tan () and hypot ()

 
# import math for math operations

import math

 

a = math.pi / 6

b = 3

c = 4

 
# returning the tangent of pi / 6

print ( "The value of tangent of pi / 6 is:" , end = "")

print (math. tan (a))

 
# returns hypotenuse 3 and 4

print ( "The value of hypotenuse of 3 and 4 is:" , end = "")

print (math.hypot ( b, c))

Output:

 The value of tangent of pi / 6 is: 0.5773502691896257 The value of hypotenuse of 3 and 4 is: 5.0 

5. degrees () : — This function is used to convert the argument value from radians to degrees .

6. radians () : — This function is used to convert the argument value from degrees to radians .

# Python code to demonstrate how it works
# degrees () and radians ()

 
# import math for math operations

import math

 

a = math.pi / 6

b = 30

 
# returns the converted value from radians to degrees

print ( " The converted value from radians to degrees is: " , end = " ")

print (math.degrees (a))

 
# returns the converted value from degrees to radians

print ( " The converted value from degrees to radians is: " , end = " ")

print (math.radians (b))

Output:

 The converted value from radians to degrees is: 29.999999999999996 The converted value from degrees to radians is: 0.5235987755982988 

This article courtesy of Manjit Singh . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method