# Problem storing $x_j$ terms in variable x [duplicate]

This works:

Table[Subscript[x, j], {j, 1, 10}]


But this doesn't:

x = Table[Subscript[x, j], {j, 1, 10}]


Giving this warning:

\$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of Subscript[x, 1]. >>

Can someone explain why this happens?

Students can do this of course:

Clear[x,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
x={x1,x2,x3,x4,x5,x6,x7,x8,x9,x10};


But what's the easiest way (for students just starting to use Mathematica) to enter x1, x2, through x100 and store them in the variable x?

• You are defining x in terms of x; hence the error. Use Indexed[] instead. Jun 23, 2016 at 19:22
• Or do xs = Array[x, 100], which is how I would do it. If you insist on Subscripts, do xs = Array[Subscript[x,#]&, 100] Jun 23, 2016 at 19:55
• Indexed or simply x[i] for the win. Jun 23, 2016 at 20:29
• @J.M. Can you please give me a complete line of code for the Indexed command, storing the answer in a variable, so I am sure of what you are suggesting? Thanks. Jun 23, 2016 at 21:33
• Closely related: (22376). Also perhaps worth reading, including the various questions linked therein: (6511) Sep 25, 2016 at 13:10

As others have said, you can't define a symbol in terms of its own DownValues or in terms of Subscripts of itself, so these both give recursion errors:

ClearAll[x]
x = Table[x[n], {n, 5}]
ClearAll[x]
x = Table[Subscript[x, n], {n, 5}]


I would suggest either of these workarounds:

ClearAll[x]
x = Table[Symbol["x" <> IntegerString[n]], {n, 5}]
(* {x1, x2, x3, x4, x5} *)


or

ClearAll[x]
xlist = Table[x[n], {n, 5}]
(* {x[1], x[2], x[3], x[4], x[5]} *)


That last one of course would work with subscripts too, although we try to discourage using subscripts for anything other than display formulas,

ClearAll[x]
xlist = Table[Subscript[x, n], {n, 5}]


• I'd like to thank you and your colleagues for some excellent help. Jun 24, 2016 at 1:16
• Jason, I marked this question as a duplicate. Please let me know if you disagree with that action. I noticed only after the final question here, though that is probably also a duplicate of others. Sep 25, 2016 at 13:08