# Why is this Hamiltonian matrix diagonal?

I've only recently started using density matrices in my work but I am confused with the following code that I have whether I am getting the right matrix:

def Hamiltonian(alpha,h):

Sx = np.array([[0,1],[1,0]])
Sy = np.array([[0,-1j],[1j,0]])
Sz = np.array([[1,0],[0,-1]])
I  = np.array([[1,0],[0,1]])

H =  (alpha*np.kron(np.kron(Sx,Sx),I))
H =+ (alpha*np.kron(np.kron(Sy,Sy),I))
H =+ (alpha*np.kron(np.kron(I,Sx),Sx))
H =+ (alpha*np.kron(np.kron(I,Sy),Sy))
H =+ (h*np.kron(np.kron(I,Sz),I))

return H


So the above gives me my Hamiltonian Function, where alpha is a real number and h is a magnetization parameter acting on one of my qubits.

I have tried the following:

H = Hamiltonian(1,0.5)
print(H)


$$\begin{bmatrix} 0.5&0&0&0&0&0&0&0 \\ 0&0.5&0&0&0&0&0&0 \\ 0&0&-0.5&0&0&0&0&0 \\ 0&0&0&-0.5&0&0&0&0 \\ 0&0&0&0&0.5&0&0&0 \\ 0&0&0&0&0&0.5&0&0 \\ 0&0&0&0&0&0&-0.5&0 \\ 0&0&0&0&0&0&0&-0.5 \end{bmatrix}$$

Why is it diagonal?

• No problem! If there's anything you don't like about them, feel free to rollback. It's also possible for me to format the tables so they display 'natively' (as opposed to being images) if you want? Also, welcome to Quantum Computing SE! Sep 28 '18 at 16:22
• Yeah I'd appreciate if you did that thank you I'm unfamiliar how. Thanks a mil Sep 28 '18 at 16:23
• It doesn't make sense to make a vector in the Hilbert space $(\mathbb{C}^2)^{\otimes 3}$ by $\mid \psi (\alpha,h) \rangle = \sum \lambda_i (\alpha,h) \mid i \rangle$ because you can always permute the eigenvalues to change the state. So you aren't getting something well defined. You have to say something else about how $\psi$ is constructed. $\mid i \rangle$ is in computational basis using binary expansion of $i \in [0,7]$ for which up/down. Sep 28 '18 at 22:18
• I dont understand what you mean Sep 29 '18 at 12:00
• You make the state $\rho$ with the eigenvalues the program spit out as $w$. But nothing stops the program from giving you $(-.5,-.5,-.5,-.5,.5,.5,.5,.5)$ instead and permuting the list of eigenvectors accordingly so they match. It isn't a vector in a Hilbert space. w is just an unordered multiset of eigenvalues. Sep 29 '18 at 19:57

Your matrix is diagonal because the + signs are on the wrong sides of the equals signs. The code below will give you the correct matrix:

alpha=1;h=0.5;

x=[0  1;  1 0 ];
y=[0 -1i; 1i 0];
z=[1  0;  0 -1];
I=eye(2);

H = alpha*kron(kron(x,x),I)+...
alpha*kron(kron(y,y),I)+...
alpha*kron(kron(I,x),x)+...
alpha*kron(kron(I,y),y)+...
h*kron(kron(I,z),I)


Here is the result:

The eigenvectors and eigenvlaues are much more complicated than what you have.

If you don't have Octave, these commands will install it, then open it:

sudo apt-get install octave
octave

• Why does that return a different result as opposed to my numpy version? Thank you for your answer I will try it and get back to you Sep 30 '18 at 0:04
• I fixed my numpy array to give this result so thanks for that. I can't upvote without 15 rep and unfortunately I didn't get a full answer yet so I can't accept it I appreciate the help Sep 30 '18 at 10:53
• I'm looking for an overall explanation of the physics as to what I need to get the density matrix. So far I've been using the outer product of the eigenvalues and I am not sure if this is right I need clarity Sep 30 '18 at 11:04
• That's fair enough man I'll do that now and you can answer it there thanks a mil Sep 30 '18 at 11:09
• I have created the new post Sep 30 '18 at 11:26