The projection operator $P$ is defined in quantum mechanics as $$ P=\sum_i^n \vert\psi_i\rangle \langle \psi_i\vert, $$
where $\vert\psi_i\rangle$ is a column vector and $(\langle \psi_i\vert=(\vert\psi_i\rangle)^*)^T$ is a row vector. The $\vert\psi_i\rangle$ that I am using are eigenvectors of a Hermitian matrix.
So here is what I am using:
{energy, states} = Eigensystem[H];
Reenergy = N[Re[energy]];
NormalizedOrderedStates = states[[Ordering[Reenergy]]];
psiket = Map[ConjugateTranspose[{#}] &,NormalizedOrderedStates[[1 ;;n]]]; (*This step turns the states into nx1 matrices*)
psibra = Map[ {#} &, NormalizedOrderedStates[[1 ;;n]]]; (*This step turns the states into 1xn matrices*)
Proj = Sum[psiket[[i]].psibra[[i]], {i, 1, n}];
The problem that I am having is that $H$ can be somewhere from 5000 by 5000 to 50000 by 50000 matrix. The above code is too slow and uses too much memory and in general doesn't feel right. Is there a better way to achieve this?
KroneckerProduct
orTensorProduct
$\endgroup$