Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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.)

share|improve this question

marked as duplicate by b.gatessucks, Artes, Sjoerd C. de Vries, m_goldberg, Mr.Wizard Sep 26 '13 at 12:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Maybe a duplicate of 21622 ? –  b.gatessucks Sep 26 '13 at 9:21

1 Answer 1

up vote 2 down vote accepted

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]
Integrate[
  Exp[-Sum[Subscript[x, i]*A[[i, j]]*Subscript[x, j], {i, 1, n}, {j, 1, n}]]
  ,Sequence @@ bounds]
share|improve this answer

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