在Python中使用NumPy对Legendre级数进行积分并设置积分的下限
在这篇文章中,我们将看到如何在Python中使用NumPy对Legendre数列进行积分并设置积分的下限。
为了进行Legendre积分,NumPy提供了一个名为 legendre.legint的函数,可以用来积分Legendre系列。
语法 : legendre.legint(c, lbnd=0, scl=1, axis=0)
参数 :
c – Legendre级数系数的数组。
lbnd – 积分的下限。(默认:0)
scl – 每次积分后,在加入积分常数之前,结果要乘以scl。(默认:1)
axis – 积分所涉及的轴。
示例 1:
在第一个例子中,让我们考虑一个有5个元素的一维数组,lbnd设置为-2。如下图所示,导入必要的包,并传递适当的参数。我们还显示了创建的NumPy数组的形状、尺寸和数据类型。
输出:
The shape of the array is (5,)
The dimension of the array is 1D
The datatype of the array is int64
Resultant series —> [220.5 8.4 2. 0.93333333 2.
1.66666667]
示例 2:
在这个例子中,让我们考虑一个有5个元素的二维数组,每个元素的lbnd设置为-1。如图所示,导入必要的包,并传递适当的参数,如下图所示。我们还将显示创建的NumPy数组的形状、尺寸和数据类型。
输出:
The shape of the array is (2, 5)
The dimension of the array is 2D
The datatype of the array is int64
Resultant series —> [[ -7.66666667 -6.33333333 -1.66666667 -212. -14.66666667]
[ 11. 12. 13. 14. 15. ]
[ 18.66666667 18.33333333 14.66666667 226. 29.66666667]]