In our Trigonometric language acos is also know as arccos. Using this we will use Matplotlib to generate graph of acos
import matplotlib.pyplot as plt
import math
x=[]
y=[]
i=-1
while (i<=1):
x.append(i)
y.append(math.acos(i))
i=i+0.01
plt.plot(x,y)
plt.show()
Example 1: Handling Invalid Inputs
import math
try:
print(math.acos(1.5)) # Will raise ValueError
except ValueError as e:
print(e) # Output: math domain error
Example 2: Calculating Angles in a Triangle
import math
a, b, c = 3, 4, 5 # sides of the triangle
angle_C = math.acos((a**2 + b**2 - c**2) / (2 * a * b))
print(math.degrees(angle_C)) # Output: 90.0 (degrees)
Example 3: Using acos() to Find an Angle in Radians
import math
cos_value = 0.5
angle = math.acos(cos_value)
print(angle) # Output: 1.0471975511965979 (in radians)
Example 4: Comparing acos() with cos()
import math
cos_value = math.cos(math.pi / 3) # cos(60 degrees)
angle = math.acos(cos_value)
print(angle) # Output: 1.0471975511965979 (radians, which is 60 degrees)
Example 5: Using acos() for Physics Calculations
import math
force_angle_cos = 0.866 # Cosine of angle between two forces
angle = math.acos(force_angle_cos)
print(math.degrees(angle)) # Output: 30 degrees