# Unable to use indexed variables with NDEigensystem

I am trying to solve a system of differential equations with NDEigensystem, but there need to be arbitrarily many of them. I want to use indexed variables like a[i], which works fine with NDSolve, but throws strange errors in NDEigensystem. Does anyone know how to get this working, or have an alternative solution? Examples below (note that I am not actually using multiple indexed variables in these minimal examples):

NDSolve, indexed symbol a[1] parsed fine, gives correct solution:

NDSolve[{-D[a[1][r], {r, 2}] + r^2*a[1][r] == 0, -b''[r] + r^2*b[r] == 0, a[1][0] == 1, a[1]'[0] == 0, b[0] == 1,b'[0] == 0}, {a[1], b}, {r, -5, 5}]


NDEigensystem, nonindexed symbol a parsed fine, gives correct solution:

NDEigensystem[{-D[a[r], {r, 2}] + r^2*a[r], -b''[r] + r^2*b[r]}, {a, b}, {r, -5, 5}, 5]


NDEigensystem, indexed symbol throws error:

NDEigensystem[{-D[a[1][r], {r, 2}] + r^2*a[1][r], -b''[r] + r^2*b[r]}, {a[1], b}, {r, -5, 5}, 5]


NDEigensystem::baddep: The dependent variables specification ({a[1]}) does not match the differential operator dependent variables.

NDEigensystem, different indexing scheme throws error:

NDEigensystem[{-D[a[1, r], {r, 2}] + r^2*a[1, r], -b''[r] + r^2*b[r]}, {a[1], b}, {r, -5, 5}, 5]


NDEigensystem::nics: Initial conditions ({(a^(0,2))[1,r]}) will be ignored.

NDEigensystem::baddep: The dependent variables specification ({a[1]}) does not match the differential operator dependent variables.

• Did you make a bug report? – Alan Aug 1 '18 at 16:09

Based on Liu's answer I'd like to suggest using:

us = Table[Symbol[StringJoin["u",
StringPadLeft[ToString[i], 2, "0"]]][t, x, y], {i, n}];


Sort[us] == us
True


That avoids issues like shown here.

This problem has been bothering me for quite some time, and I still do not know why subscripts do not work.

But the following solution could serve as a work around:

aList = Table[Symbol[StringJoin["a", ToString[i]]][r], {i, 4}]
(*Output: {a1[r], a2[r], a3[r], a4[r]}*)


Now you can use a1, a2, a3... in stead of a[1], a[2], a[3],...

• Please also refer to user21's answer. This kind of definition will meet a problem of ordering of dependent variable. Better to make it a01,a02...a10 if your number of dependent variable is larger than two digits. – Xiaoyu Liu Mar 15 '18 at 9:43