Re: Creating a symmetric matrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg47002] Re: Creating a symmetric matrix*From*: drbob at bigfoot.com (Bobby R. Treat)*Date*: Fri, 19 Mar 2004 01:35:55 -0500 (EST)*References*: <c2p9ld$dns$1@smc.vnet.net> <200403130440.XAA15145@smc.vnet.net> <A8166766-7689-11D8-A63D-0003938BF55C@jeol.com> <c36baq$s26$1@smc.vnet.net> <c3bfgk$7i5$1@smc.vnet.net> <c3bqrj$f2f$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

The problem with that, I think, is that it replaces n(n+1)/2 elements (some of which may be zeroes) with n^2 rules. The result has Head equal to SparseArray, true, but it's anything but sparse. Bobby Paul Abbott <paul at physics.uwa.edu.au> wrote in message news:<c3bqrj$f2f$1 at smc.vnet.net>... > In article <c3bfgk$7i5$1 at smc.vnet.net>, > Paul Abbott <paul at physics.uwa.edu.au> wrote: > > > In article <c36baq$s26$1 at smc.vnet.net>, DrBob <drbob at bigfoot.com> > > wrote: > > > > > Building a matrix that large (2000x2000), when half the information is > > > redundant, is probably a bad idea in the first place; and that applies to > > > the upper-triangular matrix you're taking it from as well. > > > > > > Instead, you should write code that uses the necessary information more > > > efficiently. > > > > > > SparseArray also may be of help. > > > > Perhaps something like > > > > Flatten[Table[{i,j} -> a[i,j],{j, 1, 4}, {i, 1, j}]]; > > > > % /. ({i_, j_} -> a_) :> {j, i} -> a; > > > > Normal[SparseArray[Join[%, %%]]] > > or maybe > > tri = Flatten[Table[{i, j} -> a[i, j], {j, 1, 4}, {i, 1, j}]] > > diag = Cases[tri, c:({i_, i_} -> a_) -> c] > > tri = SparseArray[tri] > > diag = SparseArray[diag] > > tri + Transpose[tri] - diag > > Normal[%] > > Cheers, > Paul

**References**:**Re: Creating a symmetric matrix***From:*drbob@bigfoot.com (Bobby R. Treat)