Introduction to Trigonometric Functions in Python
The real functions used to relate the angle of a right-angled triangle to the ratios of lengths of the two sides are called trigonometric functions. Trigonometric functions are used in the field of science related to geometry such as navigation, solid mechanics, celestial mechanics, geodesy, etc. The standard module in python is the math module and is always available. The math module consists of mathematical functions and these functions can be imported using import math. Complex data types are not supported by this module. The Cmath module is used to support complex data.
Trigonometric calculations can be performed in python by using built-in functions defined in the math module. By using the math module in python, the number of lines in the code can be reduced to a minimum. We can either import the math module or use the dot operator with a math library to use trigonometric functions.
- To import the math module,
Import math
- To reference the math library with the dot operator,
Math.function_name(parameter)
Two helper methods can be used to convert the values in radians to degrees and degrees to radians. They are:
- degrees(value)
The passed value in radians is converted to degrees by using this method.
- radians(value)
The passed value in degrees is converted to radians by using this method.
Top Trigonometric Functions in Python
There are several trigonometric functions in python. They are:
1. sin(x) Function
The sine of the value which is passed as an argument to this function is returned. Here x is passed as an argument. The input value x must be an angle expressed in terms of radians.
4.8 (7,888 ratings)
View Course
Code:
import math
x = 1
print(math.sin(x));
Output:
2. cos(x) Function
The cosine of the value which is passed as an argument to this function is returned. Here x is passed as an argument. The input value x must be an angle expressed in terms of radians.
Code:
import math
x = 1
print(math.cos(x));
Output:
3. tan(x) Function
The tangent of the value, (i.e. sine/cosine) which is passed as an argument to this function is returned. Here x is passed as an argument. The input value x must be an angle expressed in terms of radians.
Code:
import math
x = 1
print(math.tan(x));
Output:
4. asin(x) Function
The inverse of the sine is returned by using this function. The inverse of the sine is also called arc sine of the complex number. The input value x must be an angle expressed in terms of radians. The input should be within the range -1 to 1. The output is returned as a floating-point number.
Code:
import math
print(math.asin(1))
Output:
5. acos(x) Function
The inverse of the cosine is returned by using this function. The inverse of the cosine is also called arc cosine of the complex number. The input value x must be an angle expressed in terms of radians. The input should be within the range -1 to 1. The output is returned as a floating-point number.
Code:
import math
print(math.acos(1))
Output:
6. atan(x) Function
The inverse of the tangent is returned by using this function. The inverse of the cosine is also called as arc tangent of the complex number. The input value x must be an angle expressed in terms of radians. The input should be within the range -1 to 1. The output is returned as a floating-point number.
Code:
import math
print(math.atan(1))
Output:
7. sin(x) Function
x is a complex number that is passed as an argument to the function. The hyperbolic sine of the angle of the value passed as an argument is returned by this method.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of hyperbolic sine is",cmath.sinh(c))
Output:
8. cosh(x) Function
x is a complex number that is passed as an argument to the function. The hyperbolic cosine of the angle of the value passed as an argument is returned by this method.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of hyperbolic sine is",cmath.cosh(c))
Output:
9. tanh(x) Function
x is a complex number that is passed as an argument to the function. The hyperbolic tangent of the angle of the value passed as an argument is returned by this method.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of hyperbolic sine is",cmath.tanh(c))
Output:
10. asinh(x) Function
The inverse of the hyperbolic sine of the complex number is returned.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of inverse hyperbolic sine is",cmath.asinh(c))
Output:
11. acosh(x) Function
The inverse of the hyperbolic cosine of the complex number is returned.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of inverse hyperbolic sine is",cmath.acosh(c))
Output:
12. atanh(x) Function
The inverse of the hyperbolic tangent of the complex number is returned.
Code:
import cmath
a = 1.0
b = 1.0
c = complex(a,b)
print("The value of inverse hyperbolic sine is",cmath.atanh(c))
Output:
Recommended Articles
This is a guide to Trigonometric Functions in Python. Here we discuss the basic concept and top 12 trigonometric functions in python along with code implementation. You may also look at the following articles to learn more-