From: Daniel Lichtblau on
dragec wrote:
> please help me with simple to apply function that will construct
> symmetric matrix from given just a half matrix with diagonal.
> Eg:
>
> From:
> 1 0 0 0
> 2 3 0 0
> 4 9 5 0
> 2 2 3 4
>
> To give:
>
> 1 2 4 2
> 2 3 9 2
> 4 9 5 3
> 2 2 3 4

Any of these should do the job.

symmetrize1[mat_] := mat + Transpose[mat] -
DiagonalMatrix[Diagonal[mat]]

symmetrize2[mat_] := With[{n=Length[mat]},
Table[If[i<j,mat[[j,i]],mat[[i,j]]], {i,n}, {j,n}]]

symmetrize3[mat_] := With[{n=Length[mat]},
Table[Join[mat[[i,1;;i]],mat[[i+1;;n,i]]], {i,n}]]

Daniel Lichtblau
Wolfram Research


From: Patrick Scheibe on
Hi,

what about

m = {{1, 0, 0, 0}, {2, 3, 0, 0}, {4, 9, 5, 0}, {2, 2, 3, 4}};
m + Transpose[LowerTriangularize[m, -1]] // MatrixForm

?

Cheers
Patrick

On Tue, 2010-06-15 at 02:29 -0400, dragec wrote:
> please help me with simple to apply function that will construct
> symmetric matrix from given just a half matrix with diagonal.
> Eg:
>
> From:
> 1 0 0 0
> 2 3 0 0
> 4 9 5 0
> 2 2 3 4
>
> To give:
>
> 1 2 4 2
> 2 3 9 2
> 4 9 5 3
> 2 2 3 4
>


From: Bob Hanlon on

SetAttributes[f, HoldAll];

f[mat_?MatrixQ] :=
Module[
{n = Length[mat]},
Table[
mat[[r, c]] = mat[[c, r]],
{r, n - 1}, {c, r + 1, n}];
m]

m = {{1, 0, 0, 0},
{2, 3, 0, 0},
{4, 9, 5, 0},
{2, 2, 3, 4}};

f[m]

{{1, 2, 4, 2}, {2, 3, 9, 2}, {4, 9, 5, 3}, {2, 2, 3, 4}}


Bob Hanlon

---- dragec <culinovic(a)gmail.com> wrote:

=============
please help me with simple to apply function that will construct
symmetric matrix from given just a half matrix with diagonal.
Eg:

From:
1 0 0 0
2 3 0 0
4 9 5 0
2 2 3 4

To give:

1 2 4 2
2 3 9 2
4 9 5 3
2 2 3 4