RE: Creating a symmetric matrix

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

```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

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