Python Numpy np.leggauss()方法

Python Numpy np.leggauss()方法

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

语法: np.leggauss(deg)
参数:
deg : [int] 样本点和权重的数量。它必须>=1。

返回:

  1. [ndarray] 包含样本点的1-D ndarray。

  2. [ndarray] 包含权重的1-D ndarray。

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程