在Python中使用给定的复根生成拉盖尔级数
要生成具有给定根的拉盖尔级数,请在Python Numpy中使用laguerre.lagfromroots()方法。该方法返回一个一维系数数组。如果所有根都是实数,则输出是实数数组,如果某些根是复数,则即使结果中的所有系数都是实数,输出也是复数。参数根是包含根的序列。
步骤
首先,导入所需的库−
from numpy.polynomial import laguerre as L
使用laguerre.lagfromroots()方法可以生成给定根数的Laguerre系列。
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,)