在 Python 中生成具有給定復根的切比雪夫級數


要生成具有給定根的切比雪夫級數,請在 Python Numpy 中使用 chebyshev.chebfromroots() 方法。該方法返回係數的 1-D 陣列。如果所有根都是實根,則 out 是一個實陣列,如果某些根是復根,則即便結果中的所有係數都是實數,out 也是複數。引數 roots 是包含根的序列。

步驟

首先,匯入所需的庫 −

from numpy.polynomial import chebyshev as C

給定復根 −

j = complex(0,1)

生成級數 −

print("Result...\n",C.chebfromroots((-j, j)))

獲取資料型別 −

print("\nType...\n",C.chebfromroots((-j, j)).dtype)

獲取形狀 −

print("\nShape...\n",C.chebfromroots((-j, j)).shape)

示例

from numpy.polynomial import chebyshev as C

# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.

# The method returns 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",C.chebfromroots((-j, j)))

# Get the datatype
print("\nType...\n",C.chebfromroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",C.chebfromroots((-j, j)).shape)

輸出

Result...
   [1.5+0.j 0. +0.j 0.5+0.j]

Type...
complex128

Shape...
(3,)

更新於: 02-Mar-2022

118 瀏覽次數

開啟您的事業

完成課程取得認證

開始
廣告