4
$\begingroup$

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!

$\endgroup$

3 Answers 3

4
$\begingroup$

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)$$

$\endgroup$
5
$\begingroup$

You could define it with

Array[Subscript[a, Min[##], Max[##]] &, {4, 4}]
$\endgroup$
4
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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