scipy.integrate.
fixed_quad#
- scipy.integrate.fixed_quad(func, a, b, args=(), n=5)[源代码]#
使用固定阶高斯求积法计算定积分。
使用 `n` 阶高斯求积法将 func 从 a 积分到 b。
- 参数:
- func可调用对象
要积分的 Python 函数或方法(必须接受向量输入)。如果积分向量值函数,返回的数组形状必须为
(..., len(x))
。- a浮点数
积分下限。
- b浮点数
积分上限。
- args元组,可选
要传递给函数的额外参数(如果有)。
- n整型,可选
求积积分的阶数。默认为 5。
- 返回:
- val浮点数
积分的高斯求积近似值
- none无
静态返回的值 None
另请参阅
示例
>>> from scipy import integrate >>> import numpy as np >>> f = lambda x: x**8 >>> integrate.fixed_quad(f, 0.0, 1.0, n=4) (0.1110884353741496, None) >>> integrate.fixed_quad(f, 0.0, 1.0, n=5) (0.11111111111111102, None) >>> print(1/9.0) # analytical result 0.1111111111111111
>>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=4) (0.9999999771971152, None) >>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=5) (1.000000000039565, None) >>> np.sin(np.pi/2)-np.sin(0) # analytical result 1.0