MathGroup Archive 2011

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

Search the Archive

Another AppendTo replacement problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118204] Another AppendTo replacement problem
  • From: Iván Lazaro <gaminster at gmail.com>
  • Date: Sat, 16 Apr 2011 07:35:17 -0400 (EDT)

Hi dear group!

I've read multiple times in this forum about the slow performance of
AppendTo with big lists. I have now a problem with it, but have not
been able to replace it properly. This is a toy version of my problem.
The code below have to be run multiple times, but it is really slow. I
wonder if somebody have an idea about this AppendTo problem.


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]], Eigenvalues[matrA[[k]]], {k, 1, 2}}]];
   }, {Nbase, 1, NumBasis}, {k, 1, 2}];

M = Sort[Results, #1[[2]] < #2[[2]] &][[1, 1]];

Thanks in advance!.


  • Prev by Date: Re: concatenate matrices?
  • Next by Date: How to define FrontEndEventActions for keyboard combinations with Shift and Alt?
  • Previous by thread: Re: Another AppendTo replacement problem
  • Next by thread: Re: Another AppendTo replacement problem