📜  Python| Numpy np.leggauss() 方法

📅  最后修改于: 2022-05-13 01:55:32.468000             🧑  作者: Mango

Python| Numpy np.leggauss() 方法

np.leggauss()计算 Gauss-legendre 正交的样本点和权重。这些样本点和权重将在区间[-1, 1]上正确地将2*deg - 1或更小的多项式与权重函数f(x) = 1积分

代码#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]))