2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ Something like Array[m, {3, 3}]? $\endgroup$ – Carl Woll May 21 at 14:55
  • $\begingroup$ 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. $\endgroup$ – Chetan Waghela May 21 at 15:09
  • $\begingroup$ 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. $\endgroup$ – High Performance Mark May 21 at 15:18
  • 2
    $\begingroup$ Please note though that Subscript is a formatting construction. For calculations, the idiomatic way is to use m[i,j]. $\endgroup$ – Marius Ladegård Meyer May 21 at 16:48
3
$\begingroup$
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) $$

$\endgroup$
  • $\begingroup$ Thanks. I am also not able to dot product this matrix with column vector. $\endgroup$ – Chetan Waghela May 21 at 17:29
  • 1
    $\begingroup$ @ChetanWaghela please write down the command that doesn't work. I cannot debug it otherwise. $\endgroup$ – Roman May 21 at 17:51
  • $\begingroup$ Only use the Subscript for display. Clear["Global`*"]; Format[m[j_, k_]] := Subscript[m, FromDigits[{j, k}]]; (mat = Array[m, {3, 3}]) // MatrixForm $\endgroup$ – Bob Hanlon May 21 at 19:48
  • $\begingroup$ @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. $\endgroup$ – Roman May 21 at 20:10
1
$\begingroup$

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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.