Re: Creating a symmetric matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg46859] Re: Creating a symmetric matrix
- From: astanoff at yahoo.fr (astanoff)
- Date: Fri, 12 Mar 2004 02:02:44 -0500 (EST)
- References: <c2p9ld$dns$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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.