The math.asin() method is used to return the arc sine(inverse sine) of a given number.
Syntax
import math
math.asin(num)
Parameter
num(required): A number for which you want to calculate the arc sine. The value of num must be in the range -1 to 1.
Return Value
It returns the arc sine value of the number in the float datatype.
If num is outside the range of -1 and 1 , it returns a ValueError.
If num is not a number , it returns TypeError.
Visual Representation
Example 1: How to Use math.asin() Method
import math
print (math.asin(0))
print (math.asin(0.37))
print (math.asin(-0.37))
print (math.asin(1))
Output
0.0
0.3790090206959508
-0.3790090206959508
1.5707963267948966
Example 2: Value outside of the range
import math
print (math.asin(1.5))
Output
ValueError: math domain error
Method 3: Plotting
import math
import matplotlib.pyplot as plt
input_arr = [-0.1215926, -0.5703939, -0.2855993,
0.1855993, 0.6703939, 0.9915926]
output_arr = []
for i in range(len(input_arr)):
output_arr.append(math.asin(input_arr[i]))
i += 1
print("Input_Array : \n", input_arr)
print("\nOutput_Array : \n", output_arr)
plt.plot(input_arr, output_arr, "go:")
plt.title("math.asin()")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
Output
Input_Array :
[-0.1215926, -0.5703939, -0.2855993, 0.1855993, 0.6703939, 0.9915926]
Output_Array :
[-0.1218942307087407, -0.6069853392793935, -0.28963171617418493,
0.18668172388430265, 0.7347395189005061, 1.4410334105761506]
That’s it.
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.