python Scipy + sympy (?) 中变量边界的二重积分 [英] Double integral with variable boundaries in python Scipy + sympy (?)

查看:94
本文介绍了python Scipy + sympy (?) 中变量边界的二重积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整的数学问题在这里.

简而言之,我想用二重积分积分一个函数.内积分有边界20x-2,外积分有边界2230.>

我知道使用 Scipy 我可以使用 scipy.integrate.nquad 计算二重积分.我想做这样的事情:

def f(x, y):返回 (x ** 2 + y ** 2)res = sp.integrate.nquad(f, [[22, 30], [20, x-2]])

有可能吗?也许还使用 sympy?

解决方案

我用 sympy 解决了:

from sympy import *x, y = 符号("x y")f = (x ** 2 + y ** 2)res = 积分(f, (y, 20, x-2), (x, 22, 30))

基本上 sympy.integrate 能够处理多个集成,也可以处理可变边界.

The full mathematical problem is here.

Briefly I want to integrate a function with a double integral. The inner integral has boundaries 20 and x-2, while the outer has boundaries 22 and 30.

I know that with Scipy I can compute the double integral with scipy.integrate.nquad. I would like to do something like this:

def f(x, y):
    return (x ** 2 + y ** 2)
res = sp.integrate.nquad(f, [[22, 30], [20, x-2]])

Is it possible? Maybe using also sympy?

解决方案

I solved with sympy:

from sympy import *

x, y = symbols("x y")
f = (x ** 2 + y ** 2)
res = integrate(f, (y, 20, x-2), (x, 22, 30))

Basically sympy.integrate is able to deal with multiple integrations, also with variable boundaries.

这篇关于python Scipy + sympy (?) 中变量边界的二重积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆