0

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?

David
  • 14,883
  • 4
  • 44
  • 117

1 Answers1

2

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

Mathematica graphics

Jason B.
  • 68,381
  • 3
  • 139
  • 286
  • I'd like to thank you and your colleagues for some excellent help. – David Jun 24 '16 at 01: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. – Mr.Wizard Sep 25 '16 at 13:08