%Schrodinger equation: Direct solver
clear all; close all;
n=201;
x=-1:2/(n-1):1;
dx=x(2)-x(1);

N0=0;
m=n-2; %size of A matrix

%Diagonals
for j=1:m
        A(j,j)=-2+dx^2*N0;
end

%off diagonals
for j=1:m-1
    A(j,j+1)=1;
    A(j+1,j)=1;
end

[V,D]=eig(A); %eigenvectors V and eigenvalues D

col=['r','b','g','c','m','k'];

for j=1:3
    eig(1)=0;%left boundary condition
    eig(2:m+1)=V(:,end+1-j);%interior points
    eig(n)=0; %right boundary condition
    norm=trapz(x,eig.^2); %normalization
    plot(x,eig/sqrt(norm),col(j));hold on %plot
    EigenValues=D(end+1-j,end+1-j)/dx/dx %write out eignevalues
end
