scipy.integrate.

fixed_quad#

scipy.integrate.fixed_quad(func, a, b, args=(), n=5)[源代码]#

使用固定阶数的 Gaussian 求积法计算定积分。

使用 n 阶的 Gaussian 求积法对 funcab 进行积分。

参数:
funccallable

要积分的 Python 函数或方法(必须接受向量输入)。如果积分一个向量值函数,则返回的数组的形状必须为 (..., len(x))

afloat

积分下限。

bfloat

积分上限。

args元组 (tuple),可选

传递给函数的额外参数(如果有)。

nint, optional

求积积分的阶数。默认值为 5。

返回:
valfloat

Gaussian 求积法对积分的近似值

noneNone

静态返回值为 None

另请参阅

quad

使用 QUADPACK 的自适应求积法

dblquad

双重积分

tplquad

三重积分

romb

针对采样数据的积分器

simpson

针对采样数据的积分器

cumulative_trapezoid

针对采样数据的累积积分

附注

数组 API 标准支持

fixed_quad 对 Python Array API 标准兼容的后端具有实验性支持,除了 NumPy 之外。请考虑通过设置环境变量 SCIPY_ARRAY_API=1 并提供 CuPy、PyTorch、JAX 或 Dask 数组作为数组参数来测试这些功能。支持以下后端和设备(或其他功能)的组合。

CPU

GPU

NumPy

不适用

CuPy

不适用

PyTorch

JAX

Dask

不适用

有关更多信息,请参阅 对数组 API 标准的支持

示例

>>> 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