# Replace elements in matrix to make it symmetric using automated procedure

I am generating a matrix using

(mat2 = Array[Subscript[a, ##] &, {4, 4}]) // MatrixForm


but would like to force Mathematica to make it symmetric. Thereby I am using

 mat2 //. {Subscript[a, 2, 1] -> Subscript[a, 1, 2]}


to replace $a_{21}$ with $a_{12}$. For the other elements, and also for higher order squares, is there an efficient way to automate this somehow?

Thanks so much!

You can apply a rule using Condition:

mat2 /. Subscript[a, i_, j_] :> Subscript[a, j, i] /; j > i


giving

$$\left( \begin{array}{cccc} a_{1,1} & a_{2,1} & a_{3,1} & a_{4,1} \\ a_{2,1} & a_{2,2} & a_{3,2} & a_{4,2} \\ a_{3,1} & a_{3,2} & a_{3,3} & a_{4,3} \\ a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} \\ \end{array} \right)$$

You could define it with

Array[Subscript[a, Min[##], Max[##]] &, {4, 4}]


Using the built-in matrix manipulation commmands

mat = Array[Subscript[a, ##] &, {4, 4}];
LowerTriangularize[mat] + Transpose[LowerTriangularize[mat]] - DiagonalMatrix[Diagonal[mat]]


gives the same answer. This takes the lower triangular part and adds it to the transpose of itself, giving a symmetric matrix in which the diagonal entries have been doubled. Hence they are subtracted out.