# Dynamicaly add multiple integrals to Manipulate

I want to use Manipulate[] for parameter n for this expression. $$\underbrace{\int\limits_\mathbb{R} \dots \int\limits_\mathbb{R}}_nf(x_1,x_2,\dots,x_n)dx_1dx_2\dots dx_n$$

The problem for me is to understand how can I dynamicaly increase the number of integrals just by moving the slider bar for n in Manipulate[] window.

P.S. I dont care about $f(x_1,x_2, \dots ,x_n)$. It can be even $const$.

One way to do it is by using Fold. I will try it on a randomly generated polynomial,

polynomial =
Sum[RandomInteger[3, 2].(x[n]^RandomInteger[5, 2]), {n, 5}]
(* 2 + 3 x^5 + x^3 + x^5 + x^3 + 3 x^5 + 3 x^5 *)


and I'll use a TraditionalForm to give a visual output,

Manipulate[
Row@Flatten[{"∫" & /@ Range[n],
"f", {"\[DifferentialD]", Subscript[x, #]} & /@ Range[n], "="}],
Fold[Integrate[#1, #2] &, polynomial, x[#] & /@ Range[n]] /.
x[a_] :> Subscript[x, a]}],
{{n, 1}, 1, 5, 1}] You could generalize it to use a different variable list, here I'm just using {x,x,...}, but it would be easy to modify it to use, for example, {α, β, γ}. It would also be easy to modify it to do definite integrals as well

• The core thing to focus on is the Fold[Integrate[#1, #2] &, polynomial, varlist] where varlist is the variables that will be integrated over. You could have a larger varlist and use Fold[Integrate[#1, #2] &, polynomial, varlist[[;;n]]] and only the first n variables will be integrated over. The rest is window dressing to make it clear visually what is being integrated. – Jason B. Mar 8 '16 at 10:15
• Thanks for such detailed answer. I am new to Mathematica and you answer is very helpful. I am going to experiment wit it a little now, to understand everything. – Samsonov D Mar 8 '16 at 10:19

With Sequence[] combined with a function to create the necessary variables should do the trick.

Manipulate[
Integrate[f@@#, Sequence@@Reverse[#]] &[Symbol["x" <> ToString[#]] & /@ Range[n]]
, {n, 1, 10, 1}] Reverse[#] provides the correct ordering of the variables. Symbol["x" <> ToString[#] & creates a numbered variable to be used. It can be replaced with something that suits your needs. By replacing that part with something like

Function[arg, Symbol[arg <> ToString[#]]] /@ {"x", "a", "b"} &


, definite Integrals are also possible.