Python - AI 助手

Python cmath.asin() 函式



Python 的 cmath.asin() 函式用於計算以弧度表示的角度的反正弦。

反正弦函式定義為正弦函式的反函式。反正弦函式的定義域在 [-1, 1] 範圍內;此函式中的每個範圍都以弧度的形式獲得。

語法

以下是 Python cmath.asin() 函式的語法:

cmath.asin(x)

引數

此函式包含 -1 到 1 範圍內的數值。如果 x 大於 1 或小於 -1,則會生成錯誤。

返回值

此函式返回 x 的反正弦值,以弧度表示。

示例 1

在以下示例中,我們正在為標準值(如“0”、“-1”和“1”)查詢反正弦函式 cmath.asin()

import cmath
zero = cmath.asin(0)
neg_one = cmath.asin(-1)
pos_one = cmath.asin(1)
print("Arc Sine value of 0:", zero)
print("Arc Sine value of -1:", neg_one)
print("Arc Sine value of 1:", pos_one)

輸出

當我們執行以上程式碼時,它會產生以下結果:

Arc Sine value of 0: 0j
Arc Sine value of -1: (-1.5707963267948966+0j)
Arc Sine value of 1: (1.5707963267948966+0j)

示例 2

這裡,我們將非標準餘弦比作為引數傳遞,然後計算這些物件的反正弦值 cmath.asin()

import cmath
x = cmath.asin(0.75)
y = cmath.asin(-0.44)
print(x,y)

輸出

結果顯示如下:

(0.848062078981481+0j) (-0.45559867339582333+0j)

示例 3

在此示例中,輸入不是複數。因此,我們將獲得 TypeError。

import cmath
cmath.asin("Welcome to TutorialsPoint")

輸出

產生的輸出如下:

Traceback (most recent call last):
  File "/home/cg/root/30462/main.py", line 2, in 
    cmath.asin("Welcome to TutorialsPoint")
TypeError: must be real number, not str
python_modules.htm
廣告