# How to create a list of symbolic variables?

I want to use n variables $$alpha[[i]]$$ (i goes from 1 to n).

I use these variable inside of a function :

SixJ1[j1_, j2_, j3_, j4_, j5_, j6_] := Module[{j},
j = {j1, j2, j3, j4, j5, j6};
Sum[alpha[[k]]*j[[k]]*(j[[k]] + 1)*
SixJSymbol[{j1, j2, j3}, {j4, j5, j6}] +
beta*opVolume[j1, j2, j3, j4, j5, j6], {k, 1, 6}]
]


The problem is that when I call this function, mathematica answers me :

"Part specification alpha[] is longer than depth of object."


I think it is because I never initialised thoose variables but I want to keep them symbolic.

How to avoid these errors ?

• How about alpha[k]? – Michael E2 Jun 14 '17 at 14:15
• I thought that to call an element of a list we needed two bracket : [[ ? – StarBucK Jun 14 '17 at 14:16
• Ok, how about alphalist = Array[k, 6]; alphalist[[k]]? (You have to name your variables somehow first.) – Michael E2 Jun 14 '17 at 14:17
• In fact your first comment intrigued me. What is the difference between alpha[k] and alpha[[k]]. I know the second is interpreted as en element of a list but I did'nt know we could only use one bracket. What mean exactly the first expression alpha[k] ? – StarBucK Jun 14 '17 at 14:20
• Oh in fact it is just the function notation... – StarBucK Jun 14 '17 at 14:22

An alternative:

 alpha = Table[Symbol["alpha" <> ToString[i]], {i, 1, n}];

ToExpression[Table[TemplateApply["alpha<*i*>"], {i, 5}]]


{alpha1, alpha2, alpha3, alpha4, alpha5}

Probably the most elegant way that solves your problem, in my opinion, is the following one:

Subscript[alpha, #] & /@ Range


or

Table[Subscript[alpha, i], {i, 10}]


If you want to create a list of "indexed" symbols, you can do it as:

ToExpression["alpha" <> ToString[#]] & /@ Range


Or you can do something like:

alpha[#] & /@ Range


, which is actually same as:

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


[[]] - this is Part[], so you can't really use this for indexing.