Re: Another AppendTo replacement problem
- To: mathgroup at smc.vnet.net
- Subject: [mg118226] Re: Another AppendTo replacement problem
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 17 Apr 2011 07:52:46 -0400 (EDT)
With that change, the Sort still doesn't work, but at least it throws an error message to let you know it! The previous Sort was comparing lists of complex numbers, but now it's trying to compare complex numbers directly. numBasis = 10000; q = matrA = ma = ConstantArray[0, 2]; m = Orthogonalize /@ RandomComplex[{-1 - I, 1 + I}, {numBasis, 2, 2}]; matr = RandomComplex[{-1 - I, 1 + I}, {2, 2}]; results = First@Last@Reap@Do[ Do[ ma[[k]] = KroneckerProduct[#, Conjugate@#] &@m[[nBase, k]]; matrA[[k]] = Chop[matr.ma[[k]]]; matrA[[k]] = matrA[[k]]/Tr[matrA[[k]].matrA[[k]]] // Chop, {k, 1, 2}]; Sow@{m[[nBase]], Total@Eigenvalues[matrA[[2]]]}, {nBase, 1, numBasis}]; m = Sort[results, #1[[2]] < #2[[2]] &][[1, 1]]; Take[results[[All, 2]], 2] {-1.07436 - 0.258959 I, -0.620512 - 0.622878 I} results[[1, 1]] == m True m = results[[Ordering[Abs@results[[All, 2]], 1], 1]] {{{0.132007 - 0.789074 I, 0.31578 - 0.510116 I}, {0.488484 - 0.348308 I, -0.778811 + 0.183078 I}}} Bobby On Sat, 16 Apr 2011 06:36:07 -0500, Iv=E1n Lazaro <gaminster at gmail.com> wrote: > I made a mistake in the code. Now it's fine. Sorry. > > NumBasis = 10000; > q = matrA = ma = Table[0, {i, 2}]; > M = RandomComplex[{-1 - I, 1 + I}, {NumBasis, 2, 2}]; > M = Map[Orthogonalize, M]; > matr = RandomComplex[{-1 - I, 1 + I}, {2, 2}] > Results = {}; > > Do[{ma[[k]] = > KroneckerProduct[M[[Nbase, k]], Conjugate[M[[Nbase, k]]]]; > matrA[[k]] = Chop[matr.ma[[k]]]; > matrA[[k]] = matrA[[k]]/Tr[matrA[[k]].matrA[[k]]] // Chop; > If[k == 2, > AppendTo[ > Results, {M[[Nbase]], Total[Eigenvalues[matrA[[k]]]]}]]; > }, {Nbase, 1, NumBasis}, {k, 1, 2}]; > > M = Sort[Results, #1[[2]] < #2[[2]] &][[1, 1]]; > > Thanks in advance! > -- DrMajorBob at yahoo.com