Spin expectation and spin-spin correlation

Hi,

I am trying to write the iDMRG algorithm in Matlab. But I have some problems calculating the local spin expectation and spin-spin correlation. I’m writing to ask where I made a mistake and how I could revise it.

It’s spin 1/2 XXZ Heisenberg chain that I am currently working on. The Hamiltonian is
H=\sum_{<ij>} \vec{S_i} \vec{S_j}
I calculated \langle S_{z, i} \rangle for each site i and spin-spin correlation matrix \langle S_{z, i} S_{z, j} \rangle.

This is how I do the calculation:

Firstly, in each DMRG step when I expand the block, I keep in track S_{z,i} operator of each site in the block, and transform them correspondingly.
For the added new site, the S_{z,i} operator is simply

kron(complex(eye(length(H))), Sz0);

where Sz0 is the Pauli z matrix, H is the Hamiltonian of the block to be expanded.
For the sites already in the block, their S_{z,i} operator is transformed as

kron(Sz(i).Sz, complex(eye(dim)));

where Sz(i).Sz is the S_{z, i} operator already kept with the block to be expanded. And dim=2 since it’s a spin 1/2 system.

Secondly, in the final step of iDMRG, I get the ground state 1D vector $$ by

[Psi, E0] = eigs(SH, 1, 'SA');

where SH is the superblock Hamiltonian.
And with the stored S_{z, i} operators of the superblock, and the ground state 1D vector Psi of super Hamiltonian, I calculate \langle S_{z, i} \rangle and \langle S_{z, i} S_{z, j} \rangle in this way:

Szi_exp = Psi' * Szi * Psi;
SziSzj_exp = Psi' * Szi * Szj * Psi;

My final results are shown as follow:

The spin expectation result doesn’t look quite wrong. But the spin-spin correlation result is clearly wrong.

Moreover, when I add a large z-direction magnetic field term to the Hamiltonian, i.e. \sum_i h {S}_{i, z}, the expectation and correlation result is:

The expectation result in h=0 case looks alright, but in large h case, the central peak is surly problematic. I don’t think it’s a coding issue, since I reverse the magnetic field direction into -z, and peak reversed.

The spin-spin correlation results are clearly wrong.

I really want to figure out what is wrong with my code. If that is too much to ask, I really hope to know if there is some important aspect missing. I’d also love to get some suggestions on your thoughts in calculating expectation and correlation values with Matlab.

Thanks.

Hi, so this forum is for asking questions about the ITensor software (itensor.org). Did you have a question about that?

It’s great that you are writing your own DMRG code, which can be rewarding but challenging. Based on the information provided it would be hard for me to guess what is causing the bug you are having but the general advice I would give is to verify each step of your code, say by comparing to an exact calculation on a small system size, or by checking properties of the state at each step that you know to be true. Also you might find it easier to first code the finite DMRG algorithm before attempting an infinite DMRG algorithm, which can be more difficult to make work correctly.