I have a multiple integral of the following form:

$$\int_{-\infty}^\infty \cdots \int_{-\infty}^\infty \exp(-\sum_{i,j=0}^n x_i A_{ij} x_j) dx_1 \cdots dx_n $$

Here, $A$ is a square matrix and $x_1 \dots x_n$ are the variables with respect to which the integration is performed.

I would like to investigate the behavior of this integral by performing this integration for various $A$, without being limited to a particular dimension for $A$. As such, I want to be able to dynamically create integration bounds (over $x_1 \dots x_n$) in Integrate. So far, I have the following:

A = {{1, 0}, {0, 1}}; (* or some other matrix, not neccessarily 2x2 *)
n = Dimensions[A][[1]];
bounds = (* magic goes here *);
output = Integrate[
  Exp[-Sum[Subscript[x, i]*A[[i, j]]*Subscript[x, j], {i, 1, n}, {j, 
      1, n}]], bounds]

I would like to know what I should put in (* magic goes here *) to get this to work. For the matrix A I have given in the code above, the magic should produce {Subscript[x, 1], -Infinity, Infinity}, {Subscript[x, 2], -Infinity, Infinity}.

I tried defining a function f[i_] := {Subscript[x, i], -Infinity, Infinity} and then setting bounds = Array[f, n], but this doesn't work because then bounds is set to the desired output, except with one extra layer of {} around it (so {{Subscript[x, 1], -Infinity, Infinity}, {Subscript[x, 2], -Infinity, Infinity}}). I'm not sure where to go from here.

If there is a better way of representing these arbitrary variables-of-integration than using Subscript[x,i] (or xCtrl-i) that makes answering this easier, please do go ahead and use that better way.

(Note: I know that this integral has a closed-form solution for certain types of matrices $A$, but I am not interested in that.)


1 Answer 1


I like this question as an application. As a programming problem it has a simple solution, but only if you know of the Sequence command

A = {{1, 0}, {0, 1}};(*or some other matrix,not neccessarily 2x2*)
n = Dimensions[A][[1]];
f[i_] := {Subscript[x, i], -Infinity, Infinity};
bounds = Array[f, n]
Integrate[g[Sequence @@ bounds[[All, 1]]], Sequence @@ bounds]
  Exp[-Sum[Subscript[x, i]*A[[i, j]]*Subscript[x, j], {i, 1, n}, {j, 1, n}]]
  ,Sequence @@ bounds]

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