Python math.asin() Method

Python math.asin() Method

  1. Syntax of Python math.asin() Method
  2. Example Codes: Use math.asin() to Compute Arcsine of a Value
  3. Example Codes: Use math.asin() to Compute Arcsine and Cosine

Python has an in-built library math module that contains utilities to perform many mathematical operations such as approximation, estimation, trigonometric operations, inverse trigonometric operations, lowest common multiple, greatest common divisor, factorial, permutation, etc.

The inverse of sine is known as arcsine or sin⁻¹θ. Theoretically, the sine of an angle θ is the ratio of its opposite side and the hypotenuse, and the domain and range of arcsine are [-1, 1] and [−π/2, π/2], respectively.

sin(θ) = (opposite side) / (hypotenuse)
arcsine(θ) = sin⁻¹((opposite side) / (hypotenuse))

This article will discuss the asin() method from the math module that helps calculate arcsine for angles.

Syntax of Python math.asin() Method

math.asin(x)

Parameters

Parameters Type Explanation
x Integer A value between -1 and 1, both inclusive.

Returns

The asin() method returns the inverse of sine or arcsine of x in radians. The result is between the range −π/2 and π/2, both inclusive.

Example Codes: Use math.asin() to Compute Arcsine of a Value

import math

print(f"arcsine({1}) : {math.asin(1)} radians")
print(f"arcsine({-1}) : {math.asin(-1)} radians")
print(f"arcsine({-0.5}) : {math.asin(-0.5)} radians")
print(f"arcsine({0.5}) : {math.asin(0.5)} radians")
print(f"arcsine({0}) : {math.asin(0)} radians")

Output:

arcsine(1) : 1.5707963267948966 radians
arcsine(-1) : -1.5707963267948966 radians
arcsine(-0.5) : -0.5235987755982989 radians
arcsine(0.5) : 0.5235987755982989 radians
arcsine(0) : 0.0 radians

The Python code above computes the inverse of sine or arcsine for 1, -1, -0.5, 0.5, and 0. Note that all the results are in the range [−π/2, π/2].

Example Codes: Use math.asin() to Compute Arcsine and Cosine

import math

x = -1
asin = math.asin(x)
print(f"arcsine({x}):", asin)
print(f"sin({asin}):", math.sin(asin))
x = 0
asin = math.asin(x)
print(f"arcsine({x}):", asin)
print(f"sin({asin}):", math.sin(asin))
x = 1
asin = math.asin(x)
print(f"arcsine({x}):", asin)
print(f"sin({asin}):", math.sin(asin))

Output:

arcsine(-1): -1.5707963267948966
sin(-1.5707963267948966): -1.0
arcsine(0): 0.0
sin(0.0): 0.0
arcsine(1): 1.5707963267948966
sin(1.5707963267948966): 1.0

The Python code above calculates the arcsine of some value x and uses its result to recalculate x using the sine function. It performs the above operation for three values, -1, 0, and 1.

Vaibhav Vaibhav avatar Vaibhav Vaibhav avatar

Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.

LinkedIn GitHub

Related Article - Python Math

  • Python math.pow() Method
  • Python Math.erf() Method
  • Python Math.erfc() Method
  • Python Math.expm1() Method
  • Python Math.fabs() Method
  • Python Math.factorial() Method