I've used the following code to implement it
import numpy as np
from scipy.linalg import eig
import matplotlib.pyplot as plt
W = 10 #width of well
n = 1000 #number of points excluding 0,W
hbar = 1;m=1 #atomic units
x = np.linspace(1,W-1,num=n) #exclusion of 0,W
h = x[1]-x[0]#step size
#Construction of the hamiltonian matrix
H = np.zeros([n,n],dtype=complex)
for i in range(n):
H[i][i] = -2
if(i-1>=0):
H[i][i-1] = 1
if(i+1<n):
H[i][i+1] = 1
H = -1*(hbar**2)/(2*m*(h**2))*H
E,V = eig(H)
plt.plot(x,np.abs(V[:][0]),'.')
plt.plot(x,np.abs(V[:][1]),'.')
plt.show()
I'm wondering why exactly this code is not optimal enough to reproduce results close to the analytical solutions, and what the source of error is.
Edit:
Output for N=10,000
However,it took about 45 min for it to run