So, I changed a bit the program to make the sparse notation disappear and i even found the lines which gave me numerical error when trying to drop the sparse notation (totally not correlated with this thread, but correlated with simplifying the program).
If I replace lines 24-26 (I edited them) with:
H_super = kron(Block_Ham, I(m)) .+ kron(I(m), Block_Ham) .- Delta*kron(Block_Sz, Block_Sz) .+ 0.5*(kron(Block_Sp, Block_Sm) .+ kron(Block_Sm, Block_Sp))
H_super .= ifelse.(abs.(H_super) .< tol_zeros, 0, H_super)
and replace the name of the matrix I’m diagonalizing with H_super as it’s already dense now, the results (which were unchanged after the edit) become:
02 | -0.37499999999999944
04 | -0.909852489876408
08 | -1.6513656592810448
16 | -0.8090672217459194
32 | -0.15496157755719603
Which are even worse (I’m comparing all these results with the analytical result. To tell the truth not exactly: I’m comparing a result I’m not printing here for simplicity, which is directly correlated with the eigenvalues)
I’m still wondering why replacing sparse(I,m,m) with I(m) inside kron changes the results as well (now the output is not sparse anymore).
However this is not correlated with the thread by itself, which is addressing a numerical issue which is presented in the program above (which works, at least when you don’t comment line 26 == when you remove (non)zeros generated by numerical noise)
The differences in the results appear after 3 iterations and the matrix is too big to be conveniently printed.