在 Python 中计算反正切

Lakshay Kapoor 2023年10月10日 Python Python Math
  1. 使用 NumPy 库中的 arctan() 函数计算 Python 中的反正切
  2. 使用 SymPy 库中的 atan() 函数计算 Python 中的反正切
  3. 使用 Math 库中的 atan() 函数计算 Python 中的反正切
在 Python 中计算反正切

在 Python 中,人们可以执行多种任务,包括加、减、除和处理矩阵等数学运算。除了所有这些运算之外,你还可以使用 Python 提供的许多库和模块来执行复杂的数学函数,例如三角运算。

本教程将向你展示如何在 Python 中计算反正切的方法。

使用 NumPy 库中的 arctan() 函数计算 Python 中的反正切

NumPy 库在 Python 中被广泛使用。它可以帮助你处理数组、矩阵、线性代数和傅立叶变换。此外,术语 NumPy 代表 Numerical Python

NumPy 库包括一个称为 arctan() 函数的操作,这是一个用于计算数组中元素反正切的数学函数。

例子:

import numpy as np

array = [-1, 0, 0.5, 1]
print("Array: ", array)

Inv_Tan = np.arctan(array)
print("Inverse Tangent values of elements in the given Array : ", Inv_Tan)

输出:

Array:  [-1, 0, 0.5, 1]
Inverse Tangent values of elements in the given Array :  [-0.78539816  0.          0.46364761  0.78539816]

此函数计算输入数组中存在的每个元素的反正切值。

使用 SymPy 库中的 atan() 函数计算 Python 中的反正切

Python 的 SymPy 库是用于符号数学和计算机代数的开源 Python 库。

SymPy 库的 atan() 函数用于计算 Python 中给定输入值的反正切值。参考下面的示例代码。

from sympy import *

inv_tan1 = atan(0)
inv_tan2 = atan(0.5)

print(inv_tan1)
print(inv_tan2)

输出:

0
0.463647609000806

使用 Math 库中的 atan() 函数计算 Python 中的反正切

Python 的 Math 库通过在 Python 中提供不同的数学常数和函数来帮助解决复杂的数学问题。

Math 库的 atan() 函数也用于计算 Python 中给定输入值的反正切值(在 -PI/2 和 PI/2 之间)。

例子:

import math

print(math.atan(0))
print(math.atan(0.5))

输出:

0.0
0.46364760900080615
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
作者: Lakshay Kapoor
Lakshay Kapoor avatar Lakshay Kapoor avatar

Lakshay Kapoor is a final year B.Tech Computer Science student at Amity University Noida. He is familiar with programming languages and their real-world applications (Python/R/C++). Deeply interested in the area of Data Sciences and Machine Learning.

LinkedIn

相关文章 - Python Math