Write Hamiltonian using kron function

20 visualizzazioni (ultimi 30 giorni)
Abhik Saha
Abhik Saha il 22 Ago 2023
Modificato: Bruno Luong il 22 Ago 2023
I have a Hamiltonian which looks like as
where \sigmaz is a pauli spin matrix. Please note here we have total spin =6. For spin half particle the basis set is two 0 or 1. Now for 6 spin we have 2^6 basis state so the hamiltonian will be 64X64 matrix. But using kron function I can not write the Hamiltonian. It would be nice if anyone can help regarding this. After that I need to calculate the eigenvalues and eigenvectors from this Hamiltonian

Risposte (2)

recent works
recent works il 22 Ago 2023
Modificato: Walter Roberson il 22 Ago 2023
The Hamiltonian you have provided is a sum of six Pauli matrices, each acting on a different spin. The Kronecker product is a way of multiplying matrices that have the same dimensions. In this case, we can use the Kronecker product to multiply the Pauli matrices together to get a single 64x64 matrix.
import numpy as np
def kron(A, B):
Returns the Kronecker product of A and B.
m, n = A.shape
p, q = B.shape
C = np.zeros((m*p, n*q))
for i in range(m):
for j in range(n):
1)*p, j*q:(j+1)*q] = A[i, j] * B
return C
H = kron(sigmaz, sigmaz) + kron(sigmaz, sigmaz)
This code first defines a function called kron(), which takes two matrices as input and returns their Kronecker product. The function then creates the Hamiltonian matrix H by multiplying two copies of the Pauli matrix sigmaz together.
Once the Hamiltonian matrix has been created, we can use the eig() function from NumPy to calculate its eigenvalues and eigenvectors. The following code does this:
eigenvalues, eigenvectors = np.linalg.eig(H)
This code first calls the eig() function, which returns the eigenvalues and eigenvectors of H as two separate arrays. The eigenvalues are stored in the eigenvalues array, and the eigenvectors are stored in the eigenvectors array.
The eigenvalues and eigenvectors of the Hamiltonian can be used to understand the energy levels and wavefunctions of the system.

Christine Tobler
Christine Tobler il 22 Ago 2023
For a 6-dimensional Kronecker product, you would want to take
Sz = [1 0; 0 -1];
I = [1 0; 0 1];
and apply the Kronecker product to them with identity matrix I for every dimension that currently isn't involved:
Sz x Sz x I x I x I x I + I x Sz x Sz x I x I x I + ... + I x I x I x I x Sz x Sz
In MATLAB, the Kronecker product of two matrices A and B is computed using kron(A, B). To apply it multiple times, it will be easiest to make a little helper function:
A1 = krond(Sz, Sz, I, I, I, I);
A2 = krond(I, Sz, Sz, I, I, I);
A3 = krond(I, I, Sz, Sz, I, I);
A4 = krond(I, I, I, Sz, Sz, I);
A5 = krond(I, I, I, I, Sz, Sz);
H = A1 + A2 + A3 + A4 + A5;
function M = krond(A, B, varargin)
M = kron(A, B);
if ~isempty(varargin)
M = krond(M, varargin{:});
You can then apply the function eig to matrix H to compute the eigenvalues and eigenvectors.
  2 Commenti
Abhik Saha
Abhik Saha il 22 Ago 2023
The if statement in the function I do not undestand. It would be nice if you can elaborate. Also since for this case I have 6 spin so A1 = krond(Sz, Sz, I, I, I, I); but if I have lets say 24 spin then how to write this hamiltonian
Bruno Luong
Bruno Luong il 22 Ago 2023
Modificato: Bruno Luong il 22 Ago 2023
@Abhik Saha it's recursive call implementation. The recursive stops if function is called with 2 input arguents A, B otherwise krond(A1, A2, .., An) computes recursivey
kron(..., kron(kron(A1,A2), A3), ..., An)
An equivalent non-recursive implementation is:
function M = krond(A, B, varargin)
M = kron(A, B);
for k=1:length(varargin)
M = kron(M, varargin{k});

Accedi per commentare.


Scopri di più su Linear Algebra in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by