使用Python生成给定根的切比雪夫级数
要生成给定根的切比雪夫级数,请使用Python的Numpy库中的chebyshev.chebfromroots()方法。该方法返回一维系数数组。如果所有根都是实数,则out是实数组,如果一些根是复数,则即使结果中的所有系数都是实数,out也是复数。参数roots是包含根的序列。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import chebyshev as C
使用Python Numpy中的chebyshev.chebfromroots()方法来生成具有给定根的Chebyshev级数。
print("Result...\n",C.chebfromroots((-1,0,1)))
获取数据类型 –
print("\nType...\n",C.chebfromroots((-1,0,1)).dtype)
获取形状−
print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)
示例
import numpy as np
from numpy.polynomial import chebyshev as C
# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.
print("Result...\n",C.chebfromroots((-1,0,1)))
# Get the datatype
print("\nType...\n",C.chebfromroots((-1,0,1)).dtype)
# Get the shape
print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)
输出
Result...
[ 0. -0.25 0. 0.25]
Type...
float64
Shape...
(4,)