Python| Numpy np.leggauss() 方法
np.leggauss()
计算 Gauss-legendre 正交的样本点和权重。这些样本点和权重将在区间[-1, 1]
上正确地将2*deg - 1
或更小的多项式与权重函数f(x) = 1
积分
Syntax : np.leggauss(deg)
Parameters:
deg :[int] Number of sample points and weights. It must be >= 1.
Return : 1.[ndarray] 1-D ndarray containing the sample points.
2.[ndarray] 1-D ndarray containing the weights.
代码#1:
# Python program explaining
# numpy.leggauss() method
# importing numpy as np
# and numpy.polynomial.legendre module as geek
import numpy as np
import numpy.polynomial.legendre as geek
# Input degree = 2
degree = 2
# using np.leggauss() method
res = geek.leggauss(degree)
# Resulting array of sample point and weight
print (res)
输出:
(array([-0.57735027, 0.57735027]), array([ 1., 1.]))
代码#2:
# Python program explaining
# numpy.leggauss() method
# importing numpy as np
# and numpy.polynomial.legendre module as geek
import numpy as np
import numpy.polynomial.legendre as geek
# Input degree
degree = 3
# using np.leggauss() method
res = geek.leggauss(degree)
# Resulting array of sample point and weight
print (res)
输出:
(array([-0.77459667, 0., 0.77459667]), array([ 0.55555556, 0.88888889, 0.55555556]))