Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

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.




  • 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