用Python计算Laguerre级数在点x上的值
要计算Laguerre级数在点x上的值,可以使用Python中的多项式.laguerre.lagval()方法,该方法需要Numpy库的支持。第一个参数是x。如果x是一个列表或元组,则将其转换为ndarray,否则将保持不变并作为标量处理。无论哪种情况,x或其元素必须支持自身以及与c的元素进行加法和乘法运算。
第二个参数是C,一个按次数n的顺序排序的系数数组,c[n]中包含了次数为n的项的系数。如果c是多维的,则剩余的索引用于枚举多个多项式。在二维情况下,可以将系数视为存储在c的列中。
第三个参数是张量(tensor),如果为True,则系数数组的形状在右侧扩展,每个x的维度都会增加一个1。对于标量而言,其维度为0。结果是,在c的每一列上都会对x的每个元素进行求值。如果为False,则将x在c的列上进行广播以进行求值。当c是多维的时,这个关键字很有用。默认值为True。
步骤
首先导入所需的库−
import numpy as np
from numpy.polynomial import laguerre as L
创建一个系数数组 –
c = np.array([1, 2, 3])
显示数组 –
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)
使用Python中的polyomial.laguerre.lagval()方法,评估在点x处的Laguerre系列。
Numpy –
print("\nResult...\n",L.lagval(1,c))
示例
import numpy as np
from numpy.polynomial import laguerre as L
# Create an array of coefficients
c = np.array([1, 2, 3])
# 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,c))
输出
Our Array...
[1 2 3]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(3,)
Result...
-0.5