I want to try to make a list of lists of variable length in the following way
varNames = Table[Subscript[x, i], {i, 1, dim}]
varRange = Table[{varNames[[i]], 1, maxRange}, {i, 1, Length[varNames]}]
Flatten[ Table[varNames, varRange], dim -1]
Here, the variables dim and maxRange are arbitrary, and I will be setting them depending on the situation.
This does not work, because
a) The Table function gives the error
Non-list iterator varRange at position 2 does not evaluate to a real numeric value.
b) The would-be iterator needs to lose it's last set of brackets, i.e.
{{x1, 1, 4}, {x2, 1, 4}, {x3, 1, 4}}
needs to be
{x1, 1, 4}, {x2, 1, 4}, {x3, 1, 4}
Ideally, for dim=3 and maxRange=4, I want to get something like
varNames = {x1, x2, x3}
varRange = {{x1, 1, 4}, {x2, 1, 4}, {x3, 1, 4}}
and the instruction would be to create a list of lists in the following way
Flatten[Table[{x1, x2, x3}, {x1, 1, 4}, {x2, 1, 4}, {x3, 1, 4} ], 2]
Is there a way to fix this or a simpler way to do what I want?
Tuples[Range[4], 3]
. Is that what you intend? Or are you looking for a list of variable names? $\endgroup$Tuples[ ]
because I am dealing with a large length (order 100 and above) list andTuples
causes the kernel to quit. I find that usingTable[]
this way avoids crashing Mathematica. $\endgroup$