Using scipy.integrate.quad to perform 3D integral

后端 未结 2 932
眼角桃花
眼角桃花 2021-01-24 08:21

Motivation for the question

I\'m trying to integrate a function f(x,y,z) over all space.

I have tried using scipy.integrate.tplquad & scipy.integrate.nquad

2条回答
  •  臣服心动
    2021-01-24 08:46

    I'm trying to integrate a function f(x,y,z) over all space.

    First of all you'll have to ask yourself why the integral should converge at all. Does it have a factor exp(-r) or exp(-r^2)? In both of these cases, quadpy (a project of mine has something for you), e.g.,

    import quadpy
    
    scheme = quadpy.e3r2.stroud_secrest_10a()
    val = scheme.integrate(lambda x: x[0]**2)
    print(val)
    
    2.784163998415853
    

提交回复
热议问题