相关疑难解决方法(0)

numpy中高斯 - 勒让德正交的不同区间

我们如何numpy.polynomial.legendre.leggauss在除了[-1, 1]?之外的时间间隔内使用NumPy包?


以下示例与scipy.integrate.quad间隔中的Gauss-Legendre方法进行比较[-1, 1].

import numpy as np
from scipy import integrate

# Define function and interval
a = -1.
b =  1.
f = lambda x: np.cos(x)

# Gauss-Legendre (default interval is [-1, 1])
deg = 6
x, w = np.polynomial.legendre.leggauss(deg)
gauss = sum(w * f(x))

# For comparison
quad, quad_err = integrate.quad(f, a, b)

print 'The QUADPACK solution: {0:.12} with error: {1:.12}'.format(quad, quad_err)
print 'Gauss-Legendre solution: {0:.12}'.format(gauss)
print 'Difference between …
Run Code Online (Sandbox Code Playgroud)

python numpy scipy numerical-integration

6
推荐指数
1
解决办法
3304
查看次数

标签 统计

numerical-integration ×1

numpy ×1

python ×1

scipy ×1