Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am trying to do something which I assume should be very simple: I want to generate a list with symbolic coefficients that looks like this:

A = {a0, a1, a2, a3, ... , a20};

And I mean to do this a lot up to an arbitrary number, so I wouldn't want to type them all. So of course when I set one of them, say a1 = 5, then it should be updated in the list, so now:

A = {a0, 5, a2, a3, ... , a20};

I might just be missing an obvious Mathematica command here that does this... Is there a way to do such a thing?

share|improve this question

marked as duplicate by Sjoerd C. de Vries, Michael E2, halirutan, Yves Klett, Artes Apr 9 '13 at 16:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You can use Symbol["a" <> ToString[#]] & /@ Range[20]. – b.gatessucks Apr 9 '13 at 12:49
Thanks, that exactly the line that I needed! (except that I used Range[0,20] as I start at 0, but never mind that) – Jelle Apr 9 '13 at 13:16
Other possible duplicates: this – Sjoerd C. de Vries Apr 9 '13 at 13:38
up vote 3 down vote accepted

Depending on the problem you are having, it is maybe enough when you create a list of {a[0], a[1], a[2], a[3], ...}. This can be done with

Array[a, 10]

or, if you like Table

Table[a[i], {i, 10}]

If you really want to create an where n is a number, then you can use Symbol to convert a string to a symbol

Table[Symbol["a" <> ToString[i]], {i, 10}]

or, if you want definitely unassigned variables and you don't care which numbers they get

Table[Unique["a"], {10}]
share|improve this answer
Ah, thank you very much! The Symbol[] command was just what I needed! – Jelle Apr 9 '13 at 13:13
What about also mentioning ToExpression? – Yves Klett Apr 9 '13 at 14:19
@YvesKlett I assume it will be closed as dup soon and in the other post ToExpression is used. – halirutan Apr 9 '13 at 15:30
Yup. I voted for that but I think your answer is nice, short and useful anyway. – Yves Klett Apr 9 '13 at 15:57

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