%
% We solve the Sturm-Liouville problem
%     y''+r^2*(1-sin(x))^2*y=0 
%     y(0)=0,  y(1)=0
% The eigenvalues are sorted in ascending order and are stored in r_num
% 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=1/N; % spatial step size
N1=N-1;
%
% We discretize the Sturm-Liouville problem as a matrix eigenvalue problem. 
%
x=[1:N-1]'*dx;
f=(1-sin(x)).^2;
tm=ones(N1,1)/dx^2;
A=spdiags([-tm, 2*tm, -tm],[-1,0,1],N1,N1);
B=spdiags(f,0,N1,N1);
%
opts.disp=0;
r2=eigs(A,B,m,'SM',opts);
r_num=sqrt(sort(r2));
ind=[1:m]';
r_asy=ind*pi/cos(1);
%
figure(1)
clf reset
plot(ind, r_num-r_asy,'*')
%
%