在 Python 中评估拉盖尔级数在 x 点列表的值
要评估拉盖尔级数在 x 点的值,请使用 Python Numpy 中的 `polynomial.laguerre.lagval()` 方法。第一个参数是 x。如果 x 是列表或元组,则将其转换为 ndarray,否则将其保持不变并视为标量。无论哪种情况,x 或其元素都必须支持自身以及 c 的元素的加法和乘法。
第二个参数 C 是一个系数数组,其顺序使得 n 次项的系数包含在 c[n] 中。如果 c 是多维的,则其余索引枚举多个多项式。在二维情况下,系数可以认为存储在 c 的列中。
第三个参数 tensor,如果为 True,则系数数组的形状在右侧扩展为 1,每个 x 维一个。标量对此操作的维数为 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)这里,x 是一个列表:
x = [5, 10, 15]
要评估拉盖尔级数在 x 点的值,请使用 Python Numpy 中的 `polynomial.laguerre.lagval()` 方法:
print("\nResult...\n",L.lagval(x,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)
# Here, x is a list
x = [5, 10, 15]
# To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python Numpy
print("\nResult...\n",L.lagval(x,c))输出
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [ 3.5 76. 223.5]
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP