# How to transform an UpperDiagonalMatrix into a symmetric matrix in Mathematica 5.2?

I have an UpperDiagonalMatrix as the following, how to transform it into a symmetric matrix in Mathematica 5.2? Note: don't use the command c += Transpose[UpperTriangularize[c, 1]], because doesn't exist the the function UpperTriangularize in Mathematica 5.2. Thank you.

c = {{c11, c12, c13, c14}, {0, c22, c23, c24}, {0, 0, c33, c34}, {0,
0, 0, c44}};


the objective:

c = {{c11, c12, c13, c14}, {c12, c22, c23, c24}, {c13, c23, c33,
c34}, {c14, c24, c34, c44}}


• Mathematica 5.2 was released 15 years ago. – user6014 Oct 11 at 14:01
• @user6014, After the version 5.2, the windows function UnitStep was split to UnitStep and HeavisideTheta, and sometimes the UnitStep gives birth to unexpected result in new version(for example Mathematica 11.3), so I always use the version 5.2 when involving the windows function. – likehust Oct 11 at 14:35
• c + Transpose@c - c IdentityMatrix[4] – OkkesDulgerci Oct 11 at 14:55
• @OkkesDulgerci, your answer is wonderful, thank you. – likehust Oct 12 at 0:08

c = {{c11, c12, c13, c14}, {0, c22, c23, c24}, {0, 0, c33, c34}, {0, 0, 0, c44}};

Table[c[[i, j]] = c[[j, i]], {i, 2, Length[c]}, {j, 1, i - 1}];

c // MatrixForm


MapIndexed[c[[## & @@ Sort@#2]] &, c, {2}]

c2 = Array[Function[, c[[##]], Orderless], Dimensions @ c]

TeXForm @ MatrixForm @ c2


$$\left( \begin{array}{cccc} \text{c11} & \text{c12} & \text{c13} & \text{c14} \\ \text{c12} & \text{c22} & \text{c23} & \text{c24} \\ \text{c13} & \text{c23} & \text{c33} & \text{c34} \\ \text{c14} & \text{c24} & \text{c34} & \text{c44} \\ \end{array} \right)$$

Also,

SetAttributes[f, Orderless]
f[i_, j_] := c[[i, j]]

c3 = Array[f, Dimensions @ c]

c3 == c2


True

and

c4 = Array[c[[##]] & @@ Sort[{##}] &, Dimensions[c]]

c4 == c2


True

All functions used are available since version 1.

a = c + Transpose[c];
Do[a[[i, i]] -= c[[i, i]], {i, 1, Length[a]}];

• Thank you, you solved my problem correctly, but, I can take only one solution as my answer. Thank you again. – likehust Oct 11 at 14:27
• @likehust You can vote Henrik's answer up by clicking the gray triangles. – xzczd Oct 12 at 7:27
• @xzczd, I have clicked the upward gray triangles of yours and Henrik's, thanks. – likehust Oct 13 at 13:35