4
$\begingroup$

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}};

enter image description here

the objective:

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

enter image description here

$\endgroup$
  • 3
    $\begingroup$ Mathematica 5.2 was released 15 years ago. $\endgroup$ – user6014 Oct 11 at 14:01
  • $\begingroup$ @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. $\endgroup$ – likehust Oct 11 at 14:35
  • 4
    $\begingroup$ c + Transpose@c - c IdentityMatrix[4] $\endgroup$ – OkkesDulgerci Oct 11 at 14:55
  • $\begingroup$ @OkkesDulgerci, your answer is wonderful, thank you. $\endgroup$ – likehust Oct 12 at 0:08
5
$\begingroup$
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

enter image description here

$\endgroup$
4
$\begingroup$
MapIndexed[c[[## & @@ Sort@#2]] &, c, {2}]
$\endgroup$
4
$\begingroup$
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.

$\endgroup$
3
$\begingroup$
a = c + Transpose[c];
Do[a[[i, i]] -= c[[i, i]], {i, 1, Length[a]}];
$\endgroup$
  • $\begingroup$ Thank you, you solved my problem correctly, but, I can take only one solution as my answer. Thank you again. $\endgroup$ – likehust Oct 11 at 14:27
  • $\begingroup$ @likehust You can vote Henrik's answer up by clicking the gray triangles. $\endgroup$ – xzczd Oct 12 at 7:27
  • $\begingroup$ @xzczd, I have clicked the upward gray triangles of yours and Henrik's, thanks. $\endgroup$ – likehust Oct 13 at 13:35

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.