# Is there an efficient way to fill in the elements of a matrix as m11,m12…etc?

I want to autofill the elements of a matrix (or list) by m11, m12, etc.

I am able to autofill using Table[] function however, I am not able to dot product using it.

• Something like Array[m, {3, 3}]? – Carl Woll May 21 at 14:55
• It somewhat works. What if I want it to be m_11 rather that m[1,1] that I am getting now (11 to be in subscript). Also I am not be to dot product with it. – Chetan Waghela May 21 at 15:09
• If you look at the documentation for the Subscript function it provides a clear example of how to create an array whose elements look like m_1,1 (where I use _ to mean subscription). As for the second part of your question, I just don't understand what it is you can't do. Perhaps an illustrative example would help. – High Performance Mark May 21 at 15:18
• Please note though that Subscript is a formatting construction. For calculations, the idiomatic way is to use m[i,j]. – Marius Ladegård Meyer May 21 at 16:48

Array[Subscript[m, FromDigits[{##}]] &, {3, 3}]


$$\left( \begin{array}{ccc} m_{11} & m_{12} & m_{13} \\ m_{21} & m_{22} & m_{23} \\ m_{31} & m_{32} & m_{33} \\ \end{array} \right)$$

• Thanks. I am also not able to dot product this matrix with column vector. – Chetan Waghela May 21 at 17:29
• @ChetanWaghela please write down the command that doesn't work. I cannot debug it otherwise. – Roman May 21 at 17:51
• Only use the Subscript for display. Clear["Global*"]; Format[m[j_, k_]] := Subscript[m, FromDigits[{j, k}]]; (mat = Array[m, {3, 3}]) // MatrixForm – Bob Hanlon May 21 at 19:48
• @BobHanlon there's nothing fundamentally wrong with working with subscripts. They are not the best idea, but also not something I'd vocally discourage. Adding a Format layer is, in my view, at least as confusing as assigning DownValues to Subscript instead of OwnValues to the subscripted symbol. – Roman May 21 at 20:10

Perhaps

Table[ToExpression["m" <> ToString[i] <> ToString[j]], {i, 1, 3}, {j,1, 3}]
(*{{m11, m12, m13}, {m21, m22, m23}, {m31, m32, m33}}*)


is what you are looking for? Here the mij are, in contrast to the Subscript` version, unique variables!