2
$\begingroup$

Let $f_n:\mathbb{R}^n \to \mathbb{R}$. I would like to know an elegant way of writing the integral $$ I_n = \int_{\mathbb{R}^n_+} f_n(x)~\mathrm{d}x $$ in Mathematica.

For fixed $n$, the best I could do was for the region $\mathbb{R}^n$ as the following code:

x = {x1,x2,x3,x4,x5,x6,x7,x8,x9};
Integrate[f[n,x], x \[Element] FullRegion[n]]

More specifically, I would like to vary $n$. Then, considering a minimal working example with $f_n(x) = \exp\left(-\sqrt{\sum_{k=1}^n x_k}\right)$ and using the HeavisideTheta function to get the positive reals, I ended up with

x = {x1, x2, x3, x4, x5, x6, x7, x8, x9};
f[n_, x_] := Exp[-Sqrt[Sum[x[[k]], {k, 1, n}]]];
int[n_] := 
  NIntegrate[Product[HeavisideTheta[x[[k]]], {k, 1, n}] f[n, x], 
   Table[x[[k]], {k, 1, n}] \[Element] FullRegion[n]];

Among the improvements, I would like to avoid the HeavisideTheta trick and defining the x={x1,x2,...,xn}.

$\endgroup$

1 Answer 1

2
$\begingroup$

Instead of using "list" variables, like x = {x1, x2, ...}, use "indexed" variables, x[1], x[2], ..., which can be easily generated with Array. Positive region can be defined, for example, via ImplicitRegion.

Clear["Global`*"];

positiveRegion[x_] := ImplicitRegion[x >= 0, x]

f[x_] := Exp[-Sqrt[Total[x]]];

int[n_] := With[{x = Array[x, n]}, Integrate[f[x], x ∈ positiveRegion[x]]];

Table[{n, int[n]}, {n, 5}]
(* {{1, 2}, {2, 12}, {3, 120}, {4, 1680}, {5, 30240}} *)
$\endgroup$

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.