-
Notifications
You must be signed in to change notification settings - Fork 169
/
testtqlb.m
55 lines (44 loc) · 1.57 KB
/
testtqlb.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Script for comparing speed an accuracy of original TQLB, optimized TQLB
% and builtin EIG command.
% Rasmus Munk Larsen, DAIMI, 1998.
n=1000;
% Use 2. order difference matrix as testproblem.
e = ones(n,1);
T = spdiags([-e 2*e -e], -1:1, n, n);
true = 4*cos(pi/2*[n:-1:1]'./(n+1)).^2;
alpha = 2*ones(n,1);
beta = -ones(n,1);
fprintf('-----------------------------------------------------------------\n')
disp('Modified tqlb:')
fprintf('\n')
tic, flops(0)
[lambda,top,bot,err] = tqlb(alpha,beta);
fprintf('Elapsed time = %f\n',toc);
fprintf('Number of flops = %f\n',flops);
fprintf('Max rel. error = %e\n',max(abs((lambda-true)./true)))
fprintf('-----------------------------------------------------------------\n')
disp('Original tqlb:')
fprintf('\n')
tic, flops(0);
[lambda2,top,bot,err2] = tqlb_orig(alpha,beta);
fprintf('Elapsed time = %f\n',toc);
fprintf('Number of flops = %f\n',flops);
fprintf('Max rel. error = %e\n',max(abs((lambda2-true)./true)))
fprintf('-----------------------------------------------------------------\n')
disp('eig:')
fprintf('\n')
tic, flops(0);
lambda1 = eig(T);
lambda1 =sort(lambda1);
fprintf('Elapsed time = %f\n',toc);
fprintf('Number of flops = %f\n',flops);
fprintf('Max rel. error = %e\n',max(abs((lambda1-true)./true)))
fprintf('-----------------------------------------------------------------\n')
disp('eig:')
fprintf('\n')
tic, flops(0);
lambda1 = eig(full(T));
lambda1 =sort(lambda1);
fprintf('Elapsed time = %f\n',toc);
fprintf('Number of flops = %f\n',flops);
fprintf('Max rel. error = %e\n',max(abs((lambda1-true)./true)))