Write Hamiltonian using kron function

18 次查看(过去 30 天)
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

回答(2 个)

recent works
recent works 2023-8-22
编辑:Walter Roberson 2023-8-22
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):
C[i*p:(i+
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 2023-8-22
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{:});
end
end
You can then apply the function eig to matrix H to compute the eigenvalues and eigenvectors.
  2 个评论
Abhik Saha
Abhik Saha 2023-8-22
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 2023-8-22
编辑:Bruno Luong 2023-8-22
@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});
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by