使用 Python 中的給定根生成拉蓋爾級數


要使用給定根生成拉蓋爾級數,請使用 Python Numpy 中的 laguerre.lagfromroots() 方法。該方法返回係數的一維陣列。如果所有根都是實的,則 out 是實的陣列,如果一些根是複數的,則即使結果中的所有係數都是實的,out 也是複數的。引數 roots 是包含根的序列。

步驟

首先,匯入必要的庫 −

from numpy.polynomial import laguerre as L

要使用給定根生成拉蓋爾級數,請使用 Python Numpy 中的 laguerre.lagfromroots() 方法 −

print("Result...\n",L.lagfromroots((-1,0,1)))

獲取資料型別 −

print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

獲取形狀 −

print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

示例

from numpy.polynomial import laguerre as L

# To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy.
# The method returns a 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.
print("Result...\n",L.lagfromroots((-1,0,1)))

# Get the datatype
print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

# Get the shape
print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

輸出

Result...
   [ 5. -17. 18. -6.]

Type...
float64

Shape...
(4,)

更新於:04-Mar-2022

102 瀏覽量

啟動您的職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.