在 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