Efficient calculation of diagonal matrix elements

I have a matrix $V$ of size $M$ in which each row $i$ is a vector $v_i$. Now I have another matrix $H$ and I would like to calculate as efficiently as possible the list of values $v_i^\dagger\cdot H\cdot v_i$ for $i \in 1\ldots M$. I tried using Thread but I couldn't figure out how to do it.

Thank you in advance for any insight.

Thread is the inappropriate tool here as it does not hold its arguments, i.e. it does not have the attribute HoldAll:

(* {Protected} *)

So, ConjugateTranspose[v].H.v evaluates before Thread can operate on it. Also, Thread will attempt to thread across H, as well, which is clearly not what you want. The correct tool to use here is Map:

Conjugate[#].H.#& /@ v

where v is the list containing your basis vectors.

Edit: Sometimes you look at one of your own answers and wonder why you are doing it the hard way, and using Map is most definitely the hard way. It is functionally correct, but it can be made simpler. First, we need to understand how vector multiplication is interpreted by Mathematica to ensure we get it right. When you enter

H.v

it is interpreted as

$$\pmatrix{H_{11} & H_{12} & \cdots \\ H_{11} & H_{12} & \cdots \\ \vdots & \vdots & \ddots}.\pmatrix{v_1 \\ v_2 \\ \vdots}$$

and

v.H

is interpreted as $v^{T}\cdot H$. So, if you have a list of vectors that you want to left multiply by a matrix, you must Transpose the list. So, using

H = {{1, 0, I}, {0, 3, 0}, {-I, 0, 1}};
{evals, evecs} = Eigensystem@H
(* {{3, 2, 0}, {{0, 1, 0}, {I, 0, 1}, {-I, 0, 1}}} *)

as our input, to get $v_i^\dagger \cdot H \cdot v_i$, we use

With[{v = Transpose@Orthogonalize@evecs},
ConjugateTranspose[v].H.v
]
(* {{3, 0, 0}, {0, 2, 0}, {0, 0, 0}} *)
• Thank you for your answer. The Map method does not have the efficiency I was looking for. I wonder if one can do better. Apr 2 '14 at 17:42
• Define efficiently. For large enough lists of vectors, Map auto compiles, and Dot and Conjugate are on the list of functions that are compilable. This won't give a speed boost, though, if the matrix or vectors are symbolic. Are they? Apr 2 '14 at 19:41