MathGroup Archive 2004

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

Search the Archive

RE: Creating a symmetric matrix


Mark,

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

(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]}];
    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 earthlink.net
http://home.earthlink.net/~djmp/



From: Mark Coleman [mailto:mark at markscoleman.com]
To: mathgroup at smc.vnet.net


Greetings,

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
symmetric?

Thanks,

Mark



  • 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