4
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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[1]^5 + x[2]^3 + x[2]^5 + x[3]^3 + 3 x[4]^5 + 3 x[5]^5 *)

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

Manipulate[
 Column[{TraditionalForm@
    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}]

enter image description here

You could generalize it to use a different variable list, here I'm just using {x[1],x[2],...}, 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

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Jason B. Mar 8 '16 at 10:15
  • $\begingroup$ 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. $\endgroup$ – Samsonov D Mar 8 '16 at 10:19
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$

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.