6
$\begingroup$

I need to Integrate a function, but let the number of dimensions vary.

Integrate[Product[Exp[-( t[[i]] )^2], {i,1,4}], options]

with

t = {u,v,x,y}

and

options = {#,-Infinity,Infinity}&/@{u,v,x,y}

but the double braces on options doesn't allow this to work. I get this for options:

{{u, -Infinity, Infinity}, {v, -Infinity, Infinity}, {x, -Infinity, Infinity}, {y, -Infinity, Infinity}}

If I want a general list of variables, can these be added as variables into integrate, with the corresponding limits? I need a variable dimension, simply taken from the length of a list.

$\endgroup$

1 Answer 1

7
$\begingroup$

You can use Sequence to eliminate a set of brackets:

t = {u, v, x, y};
Integrate[
    Product[
        Exp[-( t[[i]] )^2],
        {i,1,4}
    ],
    Sequence @@ ({#,-Infinity,Infinity}&/@t)
]

π^2

However, it is simpler to use a Region specification instead:

Integrate[Exp[-p.p], p ∈ FullRegion[4]]

π^2

$\endgroup$
3
  • $\begingroup$ Thank you very much. Is p a vector, hence FullRegion[4]? $\endgroup$
    – apg
    Jun 26, 2019 at 18:20
  • 1
    $\begingroup$ @AlexanderKartun-Giles Yes, p is a symbolic vector. $\endgroup$
    – Carl Woll
    Jun 26, 2019 at 18:21
  • $\begingroup$ Ok I will look that up. Thank you. $\endgroup$
    – apg
    Jun 26, 2019 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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