Now the code is working well. I have implemented writing to files and found a pmax that gives good eigenvalues.