在 Python 中生成具有给定复根的勒让德级数
如果要生成勒让德级数,请在 Python 中使用 polynomial.legendre.legfromroots() 方法。该方法返回系数的 1 维数组。如果所有根都是实数,则 out 是一个实数数组;如果有些根是复数,则 out 是复数,即使结果中的所有系数都是实数。参数 roots 是包含根的序列。
步骤
首先,导入所需的库 −
from numpy.polynomial import legendre as L
在 Python 中使用 polynomial.legendre.legfromroots() 方法生成勒让德级数 −
j = complex(0,1)
print("Result...\n",L.legfromroots((-j, j)))获取数据类型 −
print("\nType...\n",L.legfromroots((-j, j)).dtype)获取形状 −
print("\nShape...\n",L.legfromroots((-j, j)).shape)示例
from numpy.polynomial import legendre as L
# To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python
j = complex(0,1)
print("Result...\n",L.legfromroots((-j, j)))
# Get the datatype
print("\nType...\n",L.legfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",L.legfromroots((-j, j)).shape)输出
Result... [1.33333333+0.j 0. +0.j 0.66666667+0.j] Type... complex128 Shape... (3,)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP