1 | % Test code for the svdj function. This function works on real, |
---|
2 | % complex and quaternion matrices, so we need to test it on more |
---|
3 | % than just quaternions. |
---|
4 | |
---|
5 | % Copyright © 2006 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
6 | % See the file : Copyright.m for further details. |
---|
7 | |
---|
8 | T = 1e-10; |
---|
9 | |
---|
10 | % This is quite a long script because of the need to test the |
---|
11 | % function with square, wide and tall arrays, and with 1 or 3 |
---|
12 | % output parameters. |
---|
13 | |
---|
14 | % Square array. |
---|
15 | |
---|
16 | display('svdj on real matrices ...') |
---|
17 | display('svdj on square array ...') |
---|
18 | |
---|
19 | A = randn(5,5); |
---|
20 | |
---|
21 | % Normal decomposition. |
---|
22 | |
---|
23 | [U, B, V] = svdj(A); |
---|
24 | compare(U*B*V', A, T, 'svdj failed test 1A') |
---|
25 | |
---|
26 | S = svdj(A); |
---|
27 | compare(S, diag(B), T, 'svdj failed test 1B') |
---|
28 | |
---|
29 | % Wide array. |
---|
30 | |
---|
31 | display('svdj on wide array ...') |
---|
32 | |
---|
33 | A = randn(5,7); |
---|
34 | |
---|
35 | % Normal decomposition. |
---|
36 | |
---|
37 | [U, B, V] = svdj(A); |
---|
38 | compare(U*B*V', A, T, 'svdj failed test 2A') |
---|
39 | |
---|
40 | S = diag(B); |
---|
41 | compare(svdj(A), S(1:5), T, 'svdj failed test 2B') |
---|
42 | |
---|
43 | % Tall array. |
---|
44 | |
---|
45 | display('svdj on tall array ...') |
---|
46 | |
---|
47 | A = A.'; |
---|
48 | |
---|
49 | % Normal decomposition. |
---|
50 | |
---|
51 | [U, B, V] = svdj(A); |
---|
52 | compare(U*B*V', A, T, 'svdj failed test 3A') |
---|
53 | |
---|
54 | S = diag(B); |
---|
55 | compare(svdj(A), S(1:5), T, 'svdj failed test 3B') |
---|
56 | |
---|
57 | |
---|
58 | % Square array. |
---|
59 | |
---|
60 | display('svdj on complex matrices ...') |
---|
61 | display('svdj on square array ...') |
---|
62 | |
---|
63 | A = complex(randn(5,5),randn(5,5)); |
---|
64 | |
---|
65 | % Normal decomposition. |
---|
66 | |
---|
67 | [U, B, V] = svdj(A); |
---|
68 | compare(U*B*V', A, T, 'svdj failed test 1A') |
---|
69 | |
---|
70 | S = svdj(A); |
---|
71 | compare(S, diag(B), T, 'svdj failed test 1B') |
---|
72 | |
---|
73 | % Wide array. |
---|
74 | |
---|
75 | display('svdj on wide array ...') |
---|
76 | |
---|
77 | A = complex(randn(5,7),randn(5,7)); |
---|
78 | |
---|
79 | % Normal decomposition. |
---|
80 | |
---|
81 | [U, B, V] = svdj(A); |
---|
82 | compare(U*B*V', A, T, 'svdj failed test 2A') |
---|
83 | |
---|
84 | S = diag(B); |
---|
85 | compare(svdj(A), S(1:5), T, 'svdj failed test 2B') |
---|
86 | |
---|
87 | % Tall array. |
---|
88 | |
---|
89 | display('svdj on tall array ...') |
---|
90 | |
---|
91 | A = A.'; |
---|
92 | |
---|
93 | % Normal decomposition. |
---|
94 | |
---|
95 | [U, B, V] = svdj(A); |
---|
96 | compare(U*B*V', A, T, 'svdj failed test 3A') |
---|
97 | |
---|
98 | S = diag(B); |
---|
99 | compare(svdj(A), S(1:5), T, 'svdj failed test 3B') |
---|
100 | |
---|
101 | |
---|
102 | % Square array. |
---|
103 | |
---|
104 | display('svdj on quaternion matrices ...') |
---|
105 | display('svdj on square array ...') |
---|
106 | |
---|
107 | A = quaternion(randn(5,5),randn(5,5),randn(5,5),randn(5,5)); |
---|
108 | |
---|
109 | % Normal decomposition. |
---|
110 | |
---|
111 | [U, B, V] = svdj(A); |
---|
112 | compare(U*B*V', A, T, 'svdj failed test 1A') |
---|
113 | |
---|
114 | S = svdj(A); |
---|
115 | compare(S, diag(B), T, 'svdj failed test 1B') |
---|
116 | |
---|
117 | % Wide array. |
---|
118 | |
---|
119 | display('svdj on wide array ...') |
---|
120 | |
---|
121 | A = quaternion(randn(5,7),randn(5,7),randn(5,7),randn(5,7)); |
---|
122 | |
---|
123 | % Normal decomposition. |
---|
124 | |
---|
125 | [U, B, V] = svdj(A); |
---|
126 | compare(U*B*V', A, T, 'svdj failed test 2A') |
---|
127 | |
---|
128 | S = diag(B); |
---|
129 | compare(svdj(A), S(1:5), T, 'svdj failed test 2B') |
---|
130 | |
---|
131 | % Tall array. |
---|
132 | |
---|
133 | display('svdj on tall array ...') |
---|
134 | |
---|
135 | A = A.'; |
---|
136 | |
---|
137 | % Normal decomposition. |
---|
138 | |
---|
139 | [U, B, V] = svdj(A); |
---|
140 | compare(U*B*V', A, T, 'svdj failed test 3A') |
---|
141 | |
---|
142 | S = diag(B); |
---|
143 | compare(svdj(A), S(1:5), T, 'svdj failed test 3B') |
---|
144 | |
---|
145 | clear A U B V S |
---|