Using tplquad to integrate over infinite values

258 views
Skip to first unread message

Cube Geometer

unread,
Jul 23, 2018, 12:23:41 AM7/23/18
to SciPy-user
Hi all,

I am doing a project in computational chemistry in which I have written some code to calculate electrical potential. The formula that I am using requires triple integrals over an infinite range of x, y, and z. The triple integrals are called as follows:

result, error = tplquad(function, (-1 * np.inf), np.inf, (-1 * np.inf), np.inf, (-1 * np.inf), np.inf, args=args)

Within the first of these function calls, another triple integral with the same formulation is called.

When this occurs, I get the following output:

Warning (from warnings module):
  File "/home/justin/.local/lib/python2.7/site-packages/scipy/integrate/quadpack.py", line 385
    warnings.warn(msg, IntegrationWarning)
IntegrationWarning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze
  the integrand in order to determine the difficulties.  If the position of a
  local difficulty can be determined (singularity, discontinuity) one will
  probably gain from splitting up the interval and calling the integrator
  on the subranges.  Perhaps a special-purpose integrator should be used.

I noticed np.inf being used as a boundary in dblquad (see https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html), so I assumed that the same was possible in tplquad. Any suggestions that anyone can provide on getting these integrals to work properly would be greatly appreciated.

Carlos Bouthelier Madre

unread,
Nov 8, 2018, 6:15:53 AM11/8/18
to SciPy-user
I know it's been a while but...
First of all, you may want to use nquad on six variables, instead of calling twice tplquad. 

Furthermore, it seems like you have some sort of discontinuity or divergence on your original function. You should check that the area you are integrating does converge when  the variables go to infinity and that there are no bad points in your function (perhaps some combination of your variables leads to a divergence. Even if the area does converge and there are no divergencies, if there are quick variations (heaviside functions, steps, or just very slopped tendencies) the integration method used by nquad() or tplquad() will not converge, because the smallest variation allowed on the variables will lead to a variation on the fuction bigger than the allowed resolution, so it will pop up that error. 

Sorry I couldn't help you more.

P.S.
I'm currently trying to solve a similar problem: if you want to integrate a function that has divergencies when a certain condition f({Arguments})=0 is fulfiled, the integral is that same integral without those points (as the divergent set is a subset of the whole space which has null measure in the integral due to its smaller dimension).  This is a very common situation in quantum chemistry and many other physical simulations and I'd like to modify  nquad in order to add this possibility, but I still don't how to do so.  If you have any ideas, I'd be helpful!
Reply all
Reply to author
Forward
0 new messages