在Python中使用给定的复根生成Chebyshev级数

在Python中使用给定的复根生成Chebyshev级数

要生成具有给定根的Chebyshev级数,在Python Numpy中使用chebyshev.chebfromroots()方法。该方法返回一个一维系数数组。如果所有根都是实数,则输出是一个实数组;如果某些根是复数,则输出是一个复数数组,即使结果中的所有系数都是实数。参数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,)

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程