How can I generate a list of variable-names like {p0, p1, p2, p3} etc...
I tried:
mylist = p # &@Range[1, 4]
But then the result is:
{p, 2 p, 3 p, 4 p}
How can I generate a list of variable-names like {p0, p1, p2, p3} etc...
I tried:
mylist = p # &@Range[1, 4]
But then the result is:
{p, 2 p, 3 p, 4 p}
ToExpression[StringJoin["p",ToString[#]]]&/@Range[4]but in general it is not recommended; the usual recommendation is to use indexed variables ie usep/@Range[4]; this seems relevant; on a different note, perhaps this is helpful, also – user42582 Jul 01 '18 at 15:30Table[StringTemplate["p``"][i], {i, 5}](see this answer) or maybeTable["p" <> IntegerString[i, 10], {i, 1, 5}]. But, as user42582 points out, it is better to consider using indexed variables. For example:Array[p, 5](but avoid subscripted variable names, as inArray[Subscript[a, #] &, {5}], as (IMO at least) these can cause problems). – user1066 Jul 01 '18 at 17:22