MathGroup Archive 2004

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

Search the Archive

Re: Creating a symmetric matrix


Mark Coleman wrote:
> 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

My solution : 
In[1]:=
symmetrize[m_]:=
    With[{mi=MapIndexed[Table[0,{#2[[1]]}]~Join~Drop[#1,#2[[1]]]&,m]},
      mi+Transpose[mi]+IdentityMatrix[Length[m]]*m
      ];
In[2]:=m={{1,2,3},{0,5,6},{0,0,9}};
In[3]:=symmetrize[m] 
Out[3]={{1,2,3},{2,5,6},{3,6,9}}

hth
--
0% de pub! Que du bonheur et des vrais adhérents !
Vous aussi inscrivez-vous sans plus tarder!!
Message posté à partir de http://www.gyptis.org, BBS actif depuis 1995.




  • Prev by Date: Undiscovered Bug?
  • Next by Date: Re: Font size
  • Previous by thread: Re: Creating a symmetric matrix
  • Next by thread: RE: Creating a symmetric matrix