%P2

clc
randn('seed',0)

% Example 1
n = 10;
T = triu(tril(randn(n,n),1),-1); T = T+T';
d = diag(schur(T)); [minV,idx] = min(abs(d)); xExact = d(idx);
a = diag(T); c = diag(T,-1); x = LambdaSmall(a,c);
fprintf('\n n = %1d\n xExact = %20.15f\n x      = %20.15f\n\n',n,xExact,x)

% Example 2
n = 100;
T = triu(tril(randn(n,n),1),-1); T = T+T';
d = diag(schur(T)); [minV,idx] = min(abs(d)); xExact = d(idx);
a = diag(T); c = diag(T,-1); x = LambdaSmall(a,c);
fprintf('\n n = %1d\n xExact = %20.15f\n x      = %20.15f\n\n',n,xExact,x)

% Example 3
n = 1000;
T = triu(tril(randn(n,n),1),-1); T = T+T';
d = diag(schur(T)); [minV,idx] = min(abs(d)); xExact = d(idx);
a = diag(T); c = diag(T,-1); x = LambdaSmall(a,c);
fprintf('\n n = %1d\n xExact = %20.15f\n x      = %20.15f\n\n',n,xExact,x)