# Numerically solving the Schrodinger equation via finite difference [closed]

This is not strictly a question about physics but about the numerical solution to a physics problem. I am solving the Schrodinger equation via finite difference, via the substitution

I solved this using Mathematica for the case that $V(x) = 0$ and get the correct eigenvalues. I find the eigenvectors and plot them via

d2dx[n_] :=
SparseArray[{Band[{1, 1}] -> -2, Band[{1, 2}] -> 1,
Band[{2, 1}] -> 1}, {n, n}]/(1/n^2);
evecs[n_, m_] := Last@Eigenvectors[N[-d2dx[n]], m]
ListPlot[evecs[100, 1], Joined -> True]
ListPlot[evecs[100, 2], Joined -> True]
ListPlot[evecs[100, 3], Joined -> True]


But the results look like this:

The profiles are correct but of course it shouldn't be oscillating in this way. Why am I seeing these oscillations and how do I get the correct eigenvectors?

## closed as off-topic by David Z♦May 23 '18 at 6:49

• This question does not appear to be about physics within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• As far as I understand, the equation itself does not fix the eigenfunction sign, so the numerical procedure may yield both signs on the same plot. If you connect only positive-valued points in the first plot, you will get a $sin(\pi x/100)$, I guess. – Vladimir Kalitvianski May 19 '18 at 17:52
• Each plot shows the last eigenvector . Have you tried plotting the first eigenvectors? I recall when I was doing this the eigenvectors started as smooth solutions and as $m$ increased they started looking like your plots. – user3502079 May 19 '18 at 18:57
• I'd refer you to this Mathematics SE Q&A on the subject of Toeplitz matrices. I'm pretty sure you'd get better answers on Mathematics SE to a question like this. – StephenG May 19 '18 at 22:57
• Or perhaps Mathematica for analysis of the code you've written. – Kyle Kanos May 20 '18 at 11:28
• Cross-site duplicate: on SE.Mathematica. – Nat May 23 '18 at 0:09

The eigenvectors are organized from greatest eigenvalue to least. The solution is to reverse the list of eigenvectors then take the m'th vector from the list. It can be fixed by replacing with
evecs[n_, m_] := Reverse[Eigenvectors[N[-d2dx[n]]]][[m]]