-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcase.m
executable file
·66 lines (56 loc) · 1.22 KB
/
testcase.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
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/local/bin/octave
% warning
warning('off')
% 3x3 Matrix A
A1 = [720,-650,710;396,-145,178;972,610,-529;];
A2 = [-25,300,300;70,-840,-840;-10,120,120;];
% generate A
y = 10^-16;
A = 1/1275*(A1*y+A2);
% test
%A = [0.1,0.2,0.3;0.1,-0.1,0;0.3,0.2,0.1;];
%
s = 111;
if s == 1
tic
for i=1:1000
[Q,H] = SVDQH(A);
end
toc
elseif s == 11
tic
for i=1:1000
[Q,H] = CompleteQH(A);
end
toc
end
% cond
cond(A)
% reference
[U,S,V] = svd(A);
Q_ref = U*V';
H_ref = V*S*V';
Q_ref'*Q_ref;
% Direct
disp('Direct')
[Q,H] = DirectQH(A);
fQ = norm(Q-Q_ref,'fro')/norm(Q_ref) % forward error in Q
fH = norm(H-H_ref,'fro')/norm(H_ref) % forward error in H
be = norm(A-Q*H,'fro')/norm(A,'fro') % back error
norm(Q'*Q-eye(3),'fro')
% SVD
disp('SVD')
[Q,H] = SVDQH(A);
fQ = norm(Q-Q_ref,'fro')/norm(Q_ref) % forward error in Q
fH = norm(H-H_ref,'fro')/norm(H_ref) % forward error in H
be = norm(A-Q*H,'fro')/norm(A,'fro') % back error
norm(Q'*Q-eye(3),'fro')
Q'*Q;
% Higham
disp('Higham')
[Q,H] = CompleteQH(A);
fQ = norm(Q-Q_ref,'fro')/norm(Q_ref) % forward error in Q
fH = norm(H-H_ref,'fro')/norm(H_ref) % forward error in H
be = norm(A-Q*H,'fro')/norm(A,'fro') % back error
norm(Q'*Q-eye(3),'fro')
Q'*Q;