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