以Python中的系数为列,在点x上评估拉盖尔级数
要在点x上评估拉盖尔级数,可以使用Python的NumPy库中的polynomial.laguerre.lagval()方法。第一个参数是x。如果x是一个列表或元组,它会被转换为ndarray,否则保持不变,视为标量。在任何情况下,x或其元素必须支持加法和乘法,包括与c的元素进行加法和乘法。
第二个参数C是一个按照顺序排列的系数数组,其中n次项的系数包含在c[n]中。如果c是多维的,则其余的索引枚举多个多项式。在二维情况下,可以将系数视为存储在c的列中。
第三个参数tensor,如果为True,则系数数组的形状在右侧扩展为一个,每个维度有一个。对于这个操作,标量的维度为0。结果是,c中的每列系数都针对x的每个元素进行评估。如果为False,则在评估中x会被广播到c的列上。当c是多维的时候,这个关键字非常有用。默认值为True。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import laguerre as L
创建一个多维系数数组 –
c = np.arange(4).reshape(2,2)
显示数组-
print("Our 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)
要在点x处评估拉盖尔级数,请在Python Numpy中使用polynomial.laguerre.lagval()方法。
print("\nResult...\n",L.lagval([1,2],c,tensor = False))
示例
import numpy as np
from numpy.polynomial import laguerre as L
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our 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 evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python Numpy
print("\nResult...\n",L.lagval([1,2],c,tensor = False))
输出
Our Array...
[[0 1]
[2 3]]
Dimensions of our Array...
2
Datatype of our Array object...
int64
Shape of our Array object...
(2, 2)
Result...
[ 0. -2.]