SciPy 积分

2019/11/07 11:41

<div class="article-child "><h2>章节</h2><ul><li class="page_item page-item-3474"><a href="https://www.qikegu.com/docs/3474">SciPy 介绍</a></li> <li class="page_item page-item-3477"><a href="https://www.qikegu.com/docs/3477">SciPy 安装</a></li> <li class="page_item page-item-3479"><a href="https://www.qikegu.com/docs/3479">SciPy 基础功能</a></li> <li class="page_item page-item-3590"><a href="https://www.qikegu.com/docs/3590">SciPy 特殊函数</a></li> <li class="page_item page-item-3484"><a href="https://www.qikegu.com/docs/3484">SciPy k均值聚类</a></li> <li class="page_item page-item-3488"><a href="https://www.qikegu.com/docs/3488">SciPy 常量</a></li> <li class="page_item page-item-3492"><a href="https://www.qikegu.com/docs/3492">SciPy fftpack(傅里叶变换)</a></li> <li class="page_item page-item-3499"><a href="https://www.qikegu.com/docs/3499">SciPy 积分</a></li> <li class="page_item page-item-3554"><a href="https://www.qikegu.com/docs/3554">SciPy 插值</a></li> <li class="page_item page-item-3558"><a href="https://www.qikegu.com/docs/3558">SciPy 输入输出</a></li> <li class="page_item page-item-3563"><a href="https://www.qikegu.com/docs/3563">SciPy 线性代数</a></li> <li class="page_item page-item-3573"><a href="https://www.qikegu.com/docs/3573">SciPy 图像处理</a></li> <li class="page_item page-item-3584"><a href="https://www.qikegu.com/docs/3584">SciPy 优化</a></li> <li class="page_item page-item-3588"><a href="https://www.qikegu.com/docs/3588">SciPy 信号处理</a></li> <li class="page_item page-item-3593"><a href="https://www.qikegu.com/docs/3593">SciPy 统计</a></li> </ul></div>

Scipy中的integrate模块提供了很多数值积分方法，例如，一重积分、二重积分、三重积分、多重积分、高斯积分等等。

一重积分

$$\int_a^bf(x)dx$$

quad的一般形式是scipy.integrate.quad(f, a, b)，其中f是求积分的函数名称，ab分别是下限和上限。

import scipy.integrate
from numpy import exp
f = lambda x:exp(-x**2)
print(i)


(0.8862269254513955, 2.3183115159980698e-14)


$$I(a,b) = \int_0^1(ax^2+b)dx$$

from scipy.integrate import quad

def f(x, a, b):
return a * (x ** 2) + b

ret = quad(f, 0, 1, args=(3, 1))
print (ret)


(2.0, 2.220446049250313e-14)


重积分

二重积分

dblquad的一般形式是scipy.integrate.dblquad(func, a, b, gfun, hfun)，其中，func是待积分函数的名称，ab是x变量的上下限，gfunhfun为定义y变量上下限的函数名称。

$$\int_0^{\frac{1}{2}}dy\int_0^{\sqrt[]{1-4y^2}}19xydx$$

import scipy.integrate
from numpy import exp
from math import sqrt
f = lambda x, y : 19*x*y
g = lambda x : 0
h = lambda y : sqrt(1-4*y**2)
i = scipy.integrate.dblquad(f, 0, 0.5, g, h)
print (i)


(0.59375, 2.029716563995638e-14)


0
0 收藏

0 评论
0 收藏
0