Write Hamiltonian using kron function
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
recent works
el 22 de Ag. de 2023
Editada: Walter Roberson
el 22 de Ag. de 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):
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 comentarios
Christine Tobler
el 22 de Ag. de 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{:});
end
end
You can then apply the function eig to matrix H to compute the eigenvalues and eigenvectors.
2 comentarios
Bruno Luong
el 22 de Ag. de 2023
Editada: Bruno Luong
el 22 de Ag. de 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});
end
end
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!