How to automatically define a time dependent array of a given dimension in mathematica
Array[Symbol["x" <> ToString @ #][t] &, 15]
{x1[t], x2[t], x3[t], x4[t], x5[t], x6[t], x7[t], x8[t], x9[t], x10[t], x11[t], x12[t], x13[t], x14[t], x15[t]}
Array[Symbol[StringJoin["y", ToString /@ {##}]][t] &, {2, 2}]
{{y11[t], y12[t]}, {y21[t], y22[t]}}
As rhermans pointed out, a better approach is
Array[x[##][t], 15]
{x[1][t], x[2][t], x[3][t], x[4][t], x[5][t], x[6][t], x[7][t], x[8][t], x[9][t], x[10][t], x[11][t], x[12][t], x[13][t], x[14][t], x[15][t]}
and
Array[y[##][t], {2,2}]
{{y[1, 1][t], y[1, 2][t]}, {y[2, 1][t], y[2, 2][t]}}
If you want x[1]
to appear as x1
, say, you can use Format
:
Format[x[a_]] := Symbol["x" <> ToString[a]]
Array[x[##][t] &, {5}]
{x1[t], x2[t], x3[t], x4[t], x5[t]}
or
Format[y[a__]] := Subscript[y, a]
Array[y[##][t] &, {2, 2}] // TeXForm
$ \left( \begin{array}{cc} y_{1,1}(t) & y_{1,2}(t) \\ y_{2,1}(t) & y_{2,2}(t) \\ \end{array} \right)$
Based on this question I would go for
Through@Array[x, 15][t]
and
Through@Flatten[Array[y, {2, 2}]][t]
or
Array[x[#][t] &, 15]
and
Array[y[#1, #2][t] &, {2, 2}]
or as suggested by @kglr, very elegant.
Array[y[##][t] &, {2, 2}]