I need to write something like

Table[Subscript[A,i] = i, {i,5}]

in order to define a set of expressions. All is OK with this, but if I try to left the number of expressions as a variable k...

Table[Subscript[A,i] = i, {i,k}]

... Mathematica doesn't allow that. ¿It is possible to write this kind of k-sized sets of expressions?

  • 1
    $\begingroup$ First note Subscript[A,i] = i is not an equation but an affectiation (= is Set, not Equal). Is this really what you want? $\endgroup$
    – user64074
    Oct 14 '19 at 11:50
  • 1
    $\begingroup$ I think your aim will be achieved simply by Subscript[A,i_]:=i. Then you get it valid for any i. Another story is that this is not an equation in Mathematica. If the expression Subscript[A,i]=i is not an equation in itself, but you simply use the expression Subscript[A,i] somewhere in your code later, this may answer your need. $\endgroup$ Oct 14 '19 at 12:01
  • $\begingroup$ OK, forget then the word "equation", and think on "expression" instead. I need to have this set of expressions, from 1 to k. $\endgroup$ Oct 14 '19 at 12:10
newA[k_] := Table[i, {i, k}]
A = newA[5]  (* {1,2,3,4,5} *)
A[[1]]  (* 1 *)

Subscripts are possible too, but it's a bad idea. Use indexing.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.