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?