Mathematical Functions

1. Trigonometric Functions
A.) sin: Trigonometric sine elementwise. It has input an angle which is in radians(2*pie rad = 360 degrees). It has some similar functions to calculate cosine, tan, the inverse of sine, degree to radian conversion.etc,. Here is a list of some useful trigonometric functions.
B.) cos: Trignometric cosine elementwise.
C.) tan: Trigonometric tan elementwise.
D.) degrees: Convert angles from degree to radians.
 

Trigonometric functions

import numpy as np

1. np.sin()

np.sin(np.pi/2.)
1.0
"""In this we are taking an array of angles in degree and calculating the sine of that, so we are converting 
them to radians first"""
np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180. )
array([0.        , 0.5       , 0.70710678, 0.8660254 , 1.        ])

2. np.cos()

## Similarly we can calulate cosine and tan of angles(degrees or radians)
np.cos(np.array((0., 30., 45.)) * np.pi / 180. )
array([1.        , 0.8660254 , 0.70710678])

3. deg2rad function for converting degree to radians

np.deg2rad(180)
3.141592653589793

Calculation of cosine using deg2rad function directly for converting into radians

np.cos(np.deg2rad(np.array((0.,30.,45.))))
array([1.        , 0.8660254 , 0.70710678])
2. Hyperbolic Functions
A.) sinh: Hyperbolic sine elementwise. It is equivalent for any value of x as- 1/2*(np.exp(x)-np.exp(-x)).
B.) cosh: Hyperbolic cosine elementwise. It is equivalent for any value of x as- 1/2*(np.exp(x)+np.exp(-x)).
C.) tanh: Hyperbolic tan elementwise. It is equivalent to any value of x as-np.sinh(x)/np.cosh(x).
 
There are many more mathematical functions for rounding, exponents, and logarithms, etc.

Leave a Comment

Your email address will not be published. Required fields are marked *