# n-fold symbolic integral in Mathematica

I am trying to compute symbolically a n-fold integral (n is a parameter of a function) over, say, the cube [0,a]^n. My code looks like this

intCube[n_, a_] := Module[{xvars, range, expression},
xvars = Table[Symbol["x" <> ToString[i]], {i, 1, n}];
range = Table[{xvars[[i]], 0, a}, {i, 1, n}];
range = Row[Riffle[range, ","]];
Print[range];
expression = Product[xvars[[i]], {i, 1, n}];
Print[expression];
Integrate[expression, range]
];


The range and the expression to integrate look both ok, however, I get an awkward result. Any ideas why ?

intCube[2, a]

{x1,0,a},{x2,0,a}
x1 x2
x1 x2 Row[{{x1, 0, a}, ",", {x2, 0, a}}]


Thanks,

Ion

• Domnule Nechita, the explanation is that Row is for formatting (display) only. Bine ai venit pe Mathematica.SE! – Szabolcs Mar 14 '12 at 21:59

Use Sequence to paste in the range in Integrate :

Remove[intCube]
intCube[n_, a_] :=
Module[{xvars, range, expression},
xvars = Table[Symbol["x" <> ToString[i]], {i, 1, n}];
range = Table[{xvars[[i]], 0, a}, {i, 1, n}];
(* range=Row[Riffle[range,","]]; *)
Print[range];
expression = Product[xvars[[i]], {i, 1, n}]; Print[expression];
Integrate[expression, Sequence @@ range]
];

{{x1,0,a},{x2,0,a}}

x1 x2

a^4/4

• Thanks mate, works like a charm. I also learned about @@, I am new to mathematica so these tips are useful to me – Ion Nechita Mar 14 '12 at 12:15
• @Ion Well, then you can go ahead and change expression using @@ – b.gates.you.know.what Mar 14 '12 at 12:17
• :) expression = Times @@ xvars; right ? – Ion Nechita Mar 14 '12 at 12:22