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.


1 Answer 1


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


it is interpreted as

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



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},
(* {{3, 0, 0}, {0, 2, 0}, {0, 0, 0}} *)
  • $\begingroup$ Thank you for your answer. The Map method does not have the efficiency I was looking for. I wonder if one can do better. $\endgroup$
    – lagoa
    Commented Apr 2, 2014 at 17:42
  • $\begingroup$ 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? $\endgroup$
    – rcollyer
    Commented Apr 2, 2014 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.