在 Python 中生成具有給定復根的拉格朗日級數
要使用給定根生成拉格朗日級數,可以使用 Python Numpy 中的 laguerre.lagfromroots() 方法。該方法是一維繫數陣列。如果所有根都是實數,則 out 是一個實數陣列;如果某些根是複數,則即使結果中的所有係數都是實數,out 也是一個複數。引數 roots 是包含根的序列。
步驟
首先,匯入所需的庫 −
from numpy.polynomial import laguerre as L
要使用給定根生成拉格朗日級數,可以使用 laguerre.lagfromroots() 方法 −
j = complex(0,1)
print("Result...\n",L.lagfromroots((-j, j)))獲取資料型別 −
print("\nType...\n",L.lagfromroots((-j, j)).dtype)獲取形狀 −
print("\nShape...\n",L.lagfromroots((-j, j)).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 is 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.
j = complex(0,1)
print("Result...\n",L.lagfromroots((-j, j)))
# Get the datatype
print("\nType...\n",L.lagfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",L.lagfromroots((-j, j)).shape)輸出
Result... [ 3.+0.j -4.+0.j 2.-0.j] Type... complex128 Shape... (3,)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP