% P3: tests EigsOfTridiag
clc
randn('seed',0)
tol = .000001;

% Do some n=10 examples and use eig to get the true eigenvalues...
n = 10; a = randn(n,1); b = randn(n-1,1);
T = diag(a);
for i=1:n-1
    T(i+1,i) = b(i);
    T(i,i+1) = b(i);
end
Lambda0 = sort(eig(T),'descend');

disp('Example 1')
% Set p = q...
Lambda1 = zeros(n,1);
for p=1:n
    Lambda1(p) = EigsOfTridiag(a,b,p,p,tol);
end
[Lambda0 Lambda1]

disp('Example 2')
% Three biggest eigenvalues...
p = 1; q = 3;
[Lambda0(q:-1:p)  EigsOfTridiag(a,b,p,q,tol)]

disp('Example 3')
% Three smallest eigenvalues...
p = 8; q = 10;
[Lambda0(q:-1:p)  EigsOfTridiag(a,b,p,q,tol)]

disp('Example 4')
% Some middle eigenvalues...
p = 3; q = 7;
[Lambda0(q:-1:p)  EigsOfTridiag(a,b,p,q,tol)]

disp('Example 5')
% An n = 100 problem, go after eigenvalues 30,...,35...

randn('seed',0);
n = 100; a = randn(n,1); b = randn(n-1,1);
T = diag(a);
for i=1:n-1
    T(i+1,i) = b(i);
    T(i,i+1) = b(i);
end
sol = [0.8847; 0.9252; 1.0547; 1.0584; 1.1030; 1.1276];
[sol EigsOfTridiag(a,b,30,35,tol)]


