$$f(x,y) = \exp \left(- \frac{1}{2}a x^2 - \frac{1}{2}c y^2 + bxy \right)$$

where $a,b,c\ge 0$. I want to integrate numerically:

$$\int_{x_0}^{x_1}\mathrm{d}x \int_{y_0}^{y_1}\mathrm{d}y \, f(x,y) x^ny^m$$

where $-\infty < x_0 < x_1 < \infty$, $-\infty < y_0 < y_1 < \infty$, and $n,m\in\{0,1,2\}$.

A naive method has problems when the peak of $f(x,y)$ is far from the rectangle of integration.

Is there a method that I can use?

  • $\begingroup$ math.stackexchange.com/q/2693671/10063 $\endgroup$ – becko Mar 16 '18 at 12:55
  • $\begingroup$ You should not cross-post. You are not even giving time for people to answer. $\endgroup$ – nicoguaro Mar 16 '18 at 14:46
  • $\begingroup$ Did you try using Gauss quadrature? $\endgroup$ – nicoguaro Mar 16 '18 at 14:47
  • $\begingroup$ @nicoguaro I already posted a similar question on stats (stats.stackexchange.com/q/328577/5536). It did not receive any reply in over a month. That's why I was a bit more aggressive this time. $\endgroup$ – becko Mar 16 '18 at 15:34
  • $\begingroup$ I haven't tried Gauss quadrature. But I have never programmed this myself, I don't know if a numerical package can do it. What weight function would you use? $\endgroup$ – becko Mar 16 '18 at 15:34

I just tried the integration algorithm that comes with scipy.integrate for double integrals (dblquad), and it seems to work just fine for your problem

from __future__ import division, print_function 
import numpy as np
from scipy.integrate import dblquad

a = 2
b = 2
c = 1
fun = lambda x, y: np.exp(-a/2*x**2 - b/2*y**2 + c*x*y)*x**3
inte2 = dblquad(fun, 1, 4, lambda y: -5, lambda y: 8)

and returns

(0.5814009878561697, 8.012117719083942e-09)

The first value is the integral and the second is an estimate of the error on the integral.

  • $\begingroup$ Does this address the question? The question in particular asks about when the peak is far from the domain of integration, whereas your example does not seem to be peaked far outside the domain. $\endgroup$ – user14717 Mar 17 '18 at 10:03
  • $\begingroup$ @user14717, since I don't have a sense of what far away means in this question I just tried a random example. $\endgroup$ – nicoguaro Mar 17 '18 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.