%
% We solve the Sturm-Liouville problem
%     y''+r^2*x*(1-x/2)^2)*y=0 
%     y(-1)=0,  y(1)=0
% The eigenvalues are sorted in ascending order and are stored in ra
% Let N be the number of grid points in numerical discretization.
% The absolute error of the m-th eigenvalue is of the order O(m^3/N^2).
%
clear
%
N=2^14;
m=64;
dx=2/N; % spatial step size
N1=N-1;
%
% We discretize the Sturm-Liouville problem as a matrix eigenvalue problem. 
%
x=-1+[1:N-1]'*dx;
f=x.*(1-x/2).^2;
tm=(2*(f>=0)-1)/dx^2;
A=spdiags([-[tm(2:N1);0], 2*tm, -[0; tm(1:N1-1)]],[-1,0,1],N1,N1);
B=spdiags(abs(f),0,N1,N1);
%
opts.disp=0;
r2=eigs(A,B,m,'SM',opts);
r2p=r2(find(r2>0));
r_num=sqrt(sort(r2p));
m2=size(r_num,1);
ind=[1:m2]';
r_asy=(-pi/4+ind*pi)*15/7;
%
figure(2)
clf reset
plot(ind, r_num-r_asy,'*')
%
%