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