在 Python 中生成具有给定复根的切比雪夫级数


要生成具有给定根的切比雪夫级数,请在 Python Numpy 中使用 chebyshev.chebfromroots() 方法。该方法返回系数的 1-D 数组。如果所有根都是实根,则 out 是一个实数组,如果某些根是复根,则即便结果中的所有系数都是实数,out 也是复数。参数 roots 是包含根的序列。

步骤

首先,导入所需的库 −

from numpy.polynomial import chebyshev as C

给定复根 −

j = complex(0,1)

生成级数 −

print("Result...\n",C.chebfromroots((-j, j)))

获取数据类型 −

print("\nType...\n",C.chebfromroots((-j, j)).dtype)

获取形状 −

print("\nShape...\n",C.chebfromroots((-j, j)).shape)

示例

from numpy.polynomial import chebyshev as C

# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.

# The method returns 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",C.chebfromroots((-j, j)))

# Get the datatype
print("\nType...\n",C.chebfromroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",C.chebfromroots((-j, j)).shape)

输出

Result...
   [1.5+0.j 0. +0.j 0.5+0.j]

Type...
complex128

Shape...
(3,)

更新于: 02-Mar-2022

118 浏览次数

开启您的事业

完成课程取得认证

开始
广告
© . All rights reserved.