So, I'm working on a project where the number of independent variables is not fixed.
Consider a problem of $N$ independent variables, $\boldsymbol{r}$.
I want to perform different things with them. Amongst them, I want to consider (multi-dimensional) integration, etc.
Variables definition
My first question regarding this topic, is the definition of the variables to perform algebraic manipulation. My first though was to use
variables[N_]:=Table[x[i],{i,1,N}]
However, in some situations, (e.g. with Block), I cannot use these variables as I use x1,x2,.... e.g.
Block[{x[1]=2},x[1]^2]
gives an error.
(my current naive solution is to use):
variables[N_] := Table[ToExpression["x" <> ToString[i]], {i, 1, N}];
Is there any more standard solution?
Sums, integrals
This question also holds for the problem of computing integrals for arbitrary dimensions.
How can I tell mathematica to compute
Integrate[f[{r1,r2,...,rn}], {r1, 0, 1}, {r2, 0, g[r1]},...,{rN, 0, h[{r1,r2,...,"rN-1"}]}]
Most of the times I will be interested in numerically compute the integral, but nevertheless, how do I tell mathematica? I tried the simple "naive"
Integrate[1, Table[{i, 0, 1}, {i, variables[3]}]]
but it gives an error.
Integrate[1, Sequence @@ Table[{i, 0, 1}, {i, variables[3]}]]
. – b.gatessucks Feb 25 at 10:53Table[Unique["x"], {5}]
to create variables. – Silvia Feb 25 at 11:06