MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Creating a symmetric matrix

  • To: mathgroup at
  • Subject: [mg46860] RE: [mg46853] Creating a symmetric matrix
  • From: "David Park" <djmp at>
  • Date: Fri, 12 Mar 2004 02:02:45 -0500 (EST)
  • Sender: owner-wri-mathgroup at


Here's one method.

maketest[n_] :=
  Module[{mat = IdentityMatrix[n], i},
    Do[Part[mat, i] = PadLeft[Table[a[i, j], {j, i, n}], n], {i, 1, n}];

(testmat = maketest[3]) // MatrixForm

triangularToSymmetric[mat_?MatrixQ] /; Equal @@ Dimensions[mat] :=
  Module[{workmat = mat + Transpose[mat], i},
    Do[Part[workmat, i, i] = Part[mat, i, i], {i, 1, Length[workmat]}];

triangularToSymmetric[testmat] // MatrixForm

I added the matrix to its transpose and then replaced the diagonal elements
from the original matrix. I wish there were a way I could replace the
diagonal elements all at once.

I'm interested in seeing the other answers you will get.

David Park
djmp at

From: Mark Coleman [mailto:mark at]
To: mathgroup at


How can I efficiently build a symmetric matrix from an upper triangular
one, i.e., extract the upper triangular elements and insert them into
the lower triangle in such a way as to make the resulting square matrix



  • Prev by Date: Integrate vs NIntegrate
  • Next by Date: RE: Font size
  • Previous by thread: RE: Creating a symmetric matrix
  • Next by thread: Re: Creating a symmetric matrix