Python math.atan() Method

The math.atan() method is used to calculate the arc tangent of a given number.

Syntax

import math
math.atan(num)

Parameter

num(required): It is a number.

Return Value

It returns the arc tangent of the number as a float, with values ranging from from -PI/2 to PI/2.

If the num is not a number, it raises TypeError.

Visual Representation

Visual Representation of Python math.atan() Method

Example 1: How to Use math.atan() Method

import math

print (math.atan(1))
print (math.atan(10))
print (math.atan(-10))
print (math.atan(22.9))

Output

0.7853981633974483
1.4711276743037345
-1.4711276743037345
1.5271559297948705

Example 2: Plotting

import matplotlib.pyplot as plt
import math

# Create a list of x values from -2 to 2
x = [i * 0.01 for i in range(-200, 201)]

# Calculate the corresponding y values
y = [math.atan(i) for i in x]

# Create a new figure
plt.figure()

# Plot x against y
plt.plot(x, y)

# Set the title
plt.title('Plot of atan(x)')

# Set the x and y axis labels
plt.xlabel('x')
plt.ylabel('atan(x)')

# Display the plot
plt.show()

Output

Plotting the math.atan() method

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.