# Creating a Symbolic Matrix

Probably very simple, but I don't know where to start with this. How do I go about creating a symbolic matrix, such as the one below?

I want to be able to use this so that any list of lists that are entered to signify a matrix can be read as having indices {i,1,m},{j,1,n}, and then I can use another rule using the terms in the matrix, ai,j.

I found an answer that mentioned SymbolicMatrix, but this no longer seems to work on the most up-to-date versions of Mathematica.

EDIT: This seems to be trickier than I first thought. Essentially, whenever I enter a list of lists, such as mat[{{1,2,3},{4,5,6},{7,8,9}], I want to be able to automatically recognise that the first list corresponds to a1,1,a1,2,a1,3, the second list to a2,1,a2,2,a2,3, and the third list (in this example) to a3,1,a3,2,a3,3.

I then aim to write a rule that, when values of I and j are selected, gives back a list of {ai,j+1, ai,j-1, ai-1,j, ai+1,j}.

• Table[Subscript[a, i, j], {i, 3}, {j, 4}] // MatrixForm – David G. Stork Jan 5 at 17:22
• Thanks, this helps a lot. Is there anyway that I can set the number of terms to be indefinite? I want the rule that I will write for the von Neumann neighborhood to work for any size of rectangular array. I tried with replacing '3' and '4' by 'm' and 'n' respectively, but get an error message that the iterator does not contain appropriate bounds. – TubularHell Jan 5 at 17:24
• Or try Array[a, {4, 5}]. – bill s Jan 5 at 17:25
• I would also second @bills suggestion to stay away from Subscript expressions and use indexed variables instead, as was shown with Array. Much cleaner to handle those a[1, 2] objects later on! – MarcoB Jan 5 at 17:37
• Or Array[Subscript[a, #1, #2] &, {4, 5}] – chris Jan 5 at 17:39

myMatrix[n_Integer, m_Integer] :=
Table[Subscript[a, i, j], {i, n}, {j, m}] // MatrixForm

myMatrix[3, 4]

• Changing Subscript[a, n, m] to Subscript[a, i, j] works. Thanks! – TubularHell Jan 5 at 17:34
• If you want a symmetric matrix: myMatrix[n_Integer, m_Integer] := Table[Subscript[a, Sequence @@ Sort[{i, j}]], {i, n}, {j, m}] // MatrixForm – chris Jan 5 at 17:38

As mentioned in the comments, it is probably easier to stay away from using subscripts, which are primarily a formatting command. Your task is readily accomplished using Array, and defining a function to extract the elements you want:

mat = Array[a, {4, 5}]
fun[m_, i_, j_] := {a[i, j + 1], a[i, j - 1], a[i - 1, j], a[i + 1, j]};


mat defines the matrix and fun extracts the specified elements. For example:

fun[mat, 3, 4]
{a[3, 5], a[3, 3], a[2, 4], a[4, 4]}