将一个Legendre级数在Python中进行幂运算
要将一个Legendre级数进行幂运算,在Python NumPy中使用polynomial.legendre.legpow()方法。该方法返回一个被提升到pow次幂的Legendre级数c。参数c是一个从低到高排序的系数序列,例如[1,2,3]表示系列P_0 + 2P_1 + 3P_2。返回一个被提升到pow次幂的Legendre级数c。参数c是一个从低到高排序的系数序列,例如[1,2,3]表示系列P_0 + 2P_1 + 3P_2。
参数c是一个按照从低到高排序的Legendre级数系数的一维数组。参数pow是将系列提升的幂次。参数maxpower是允许的最大幂次。主要用于限制级数的增长,以防止级数过大而无法处理。默认值为16。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import laguerre as L
创建拉盖尔级数系数的一维数组 −
c = np.array([1,2,3])
显示系数数组 −
print("Our coefficient Array...\n",c)
检查尺寸 –
print("\nDimensions of our Array...\n",c.ndim)
获取数据类型 –
print("\nDatatype of our Array object...\n",c.dtype)
获取形状 −
print("\nShape of our Array object...\n",c.shape)
将一个Legendre级数升幂,可以在Python的polynomial.legendre.legpow()方法中使用。Numpy −
print("\nResult....\n",L.legpow(c, 3))
示例
import numpy as np
from numpy.polynomial import legendre as L
# Create 1-D arrays of Laguerre series coefficients
c = np.array([1,2,3])
# Display the coefficient array
print("Our coefficient Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# To raise a Legendre series to a power, use the polynomial.legendre.legpow() method in Python Numpy
# The method returns the Legendre series c raised to the power pow. The argument c is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series P_0 + 2*P_1 + 3*P_2.
print("\nResult....\n",L.legpow(c, 3))
输出
Our coefficient Array...
[1 2 3]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(3,)
Result....
[16.74285714 42.17142857 55.14285714 46.4 33.8025974 15.42857143 6.31168831]