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
0 个评论
回答(2 个)
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.
.
0 个评论
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 个评论
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!