Re: How to construct symmetric matrix from just a one half matrix
- To: mathgroup at smc.vnet.net
 - Subject: [mg110388] Re: How to construct symmetric matrix from just a one half matrix
 - From: Sseziwa Mukasa <mukasa at jeol.com>
 - Date: Wed, 16 Jun 2010 05:38:48 -0400 (EDT)
 
On Jun 15, 2010, at 2:29 AM, 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
> 
(Debug) In[76]:= lowerTriangulartoSymmetric[a_] := 
 Array[If[#2 > #1, a[[#2, #1]], a[[#1, #2]]] &, Dimensions[a]]
lowerTriangulartoSymmetric[{{1, 0, 0, 0}, {2, 3, 0, 0}, {4, 9, 5, 0}, {2, 2, 
   3, 4}}]
(Debug) Out[77]= {{1, 2, 4, 2}, {2, 3, 9, 2}, {4, 9, 5, 3}, {2, 2, 3, 4}}
Regards,
	Ssezi