Mercurial > octave-nkf
annotate test/test_linalg.m @ 7515:f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 22 Feb 2008 15:50:51 +0100 |
parents | 83a8781b529d |
children | 5502b815a556 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2006, 2007 John W. Eaton |
7016 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
5590 | 19 %% Automatically generated from DejaGNU files |
20 | |
21 %% test/octave.test/linalg/det-1.m | |
22 %!assert(det ([1, 2; 3, 4]) == -2); | |
23 | |
24 %% test/octave.test/linalg/det-2.m | |
5751 | 25 %!error <Invalid call to det.*> det (); |
5590 | 26 |
27 %% test/octave.test/linalg/det-3.m | |
5751 | 28 %!error <Invalid call to det.*> det (1, 2); |
5590 | 29 |
30 %% test/octave.test/linalg/det-4.m | |
31 %!error det ([1, 2; 3, 4; 5, 6]); | |
32 | |
33 %% test/octave.test/linalg/eig-1.m | |
34 %!assert(all (abs (eig ([1, 2; 2, 1]) - [-1; 3]) < sqrt (eps))); | |
35 | |
36 %% test/octave.test/linalg/eig-2.m | |
37 %!test | |
38 %! [v, d] = eig ([1, 2; 2, 1]); | |
39 %! x = 1 / sqrt (2); | |
40 %! assert(((abs (d - [-1, 0; 0, 3]) < sqrt (eps)) | |
41 %! && (abs (v - [-x, x; x, x]) < sqrt (eps)))); | |
42 | |
43 %% test/octave.test/linalg/eig-3.m | |
5751 | 44 %!error <Invalid call to eig.*> eig (); |
5590 | 45 |
46 %% test/octave.test/linalg/eig-4.m | |
5751 | 47 %!error <Invalid call to eig.*> eig ([1, 2; 3, 4], 2); |
5590 | 48 |
49 %% test/octave.test/linalg/eig-5.m | |
50 %!error eig ([1, 2; 3, 4; 5, 6]); | |
51 | |
52 %% test/octave.test/linalg/expm-1.m | |
53 %!test | |
54 %! arg = [-49, 24; -64, 31]; | |
55 %! result = [-0.735758758144742, 0.551819099658089; | |
56 %! -1.471517599088239, 1.103638240715556]; | |
57 %! assert(all (all (abs (expm (arg) - result) < 128*eps))); | |
58 | |
59 %% test/octave.test/linalg/expm-2.m | |
60 %!test | |
61 %! arg = [1, 1; 0, 1]; | |
62 %! result = [2.718281828459045, 2.718281828459045; | |
63 %! 0.000000000000000, 2.718281828459045]; | |
64 %! assert(all (all (abs (expm (arg) - result) < 4*eps))); | |
65 | |
66 %% test/octave.test/linalg/expm-3.m | |
67 %!test | |
68 %! arg = diag ([6, 6, 6], 1); | |
69 %! result = [1, 6, 18, 36; | |
70 %! 0, 1, 6, 18; | |
71 %! 0, 0, 1, 6; | |
72 %! 0, 0, 0, 1]; | |
73 %! assert(all (all (expm (arg) == result))); | |
74 | |
75 %% test/octave.test/linalg/expm-4.m | |
5751 | 76 %!error <Invalid call to expm.*> expm(); |
5590 | 77 |
78 %% test/octave.test/linalg/expm-5.m | |
5751 | 79 %!error <Invalid call to expm.*> expm(1,2); |
5590 | 80 |
81 %% test/octave.test/linalg/expm-6.m | |
82 %% test/octave.test/linalg/inv-1.m | |
83 %!assert(all (all (abs (inv ([1, 2; 3, 4]) - [-2, 1; 1.5, -0.5]) < sqrt (eps)))); | |
84 | |
85 %% test/octave.test/linalg/inv-2.m | |
5751 | 86 %!error <Invalid call to inv.*> inv (); |
5590 | 87 |
88 %% test/octave.test/linalg/inv-3.m | |
5751 | 89 %!error <Invalid call to inv.*> inv ([1, 2; 3, 4], 2); |
5590 | 90 |
91 %% test/octave.test/linalg/inv-4.m | |
92 %!error inv ([1, 2; 3, 4; 5, 6]); | |
93 | |
94 %% test/octave.test/linalg/chol-1.m | |
95 %!test | |
96 %! rt2 = sqrt (2); | |
97 %! assert(all (all (abs (chol ([2, 1; 1, 1]) - [rt2, 1/rt2; 0, 1/rt2]) < sqrt (eps)))); | |
98 | |
99 %% test/octave.test/linalg/chol-2.m | |
100 %!error chol ([1, 2; 3, 4]); | |
101 | |
102 %% test/octave.test/linalg/chol-3.m | |
103 %!error chol ([1, 2; 3, 4; 5, 6]); | |
104 | |
105 %% test/octave.test/linalg/chol-4.m | |
5751 | 106 %!error <Invalid call to chol.*> chol (); |
5590 | 107 |
108 %% test/octave.test/linalg/chol-5.m | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
109 %!error <unexpected second or third input.*> chol (1, 2); |
5590 | 110 |
111 %% test/octave.test/linalg/hess-1.m | |
112 %!test | |
113 %! a = [1, 2, 3; 5, 4, 6; 8, 7, 9]; | |
114 %! [p, h] = hess (a); | |
115 %! assert(size (p) == [3, 3] && size (h) == [3, 3] && abs (a - p * h * p') < sqrt (eps)); | |
116 | |
117 %% test/octave.test/linalg/hess-2.m | |
5751 | 118 %!error <Invalid call to hess.*> hess (); |
5590 | 119 |
120 %% test/octave.test/linalg/hess-3.m | |
5751 | 121 %!error <Invalid call to hess.*> hess ([1, 2; 3, 4], 2); |
5590 | 122 |
123 %% test/octave.test/linalg/hess-4.m | |
124 %!error hess ([1, 2; 3, 4; 5, 6]); | |
125 | |
126 %% test/octave.test/linalg/lu-1.m | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
127 %!assert(all (all (lu ([1, 2; 3, 4]) - [3, 4; 1/3, 2/3] < eps))); |
5590 | 128 |
129 %% test/octave.test/linalg/lu-2.m | |
130 %!test | |
131 %! [l, u] = lu ([1, 2; 3, 4]); | |
132 %! assert(((abs (l - [1/3, 1; 1, 0]) < sqrt (eps)) | |
133 %! && abs (u - [3, 4; 0, 2/3]) < sqrt (eps))); | |
134 | |
135 %% test/octave.test/linalg/lu-3.m | |
136 %!test | |
137 %! [l, u, p] = lu ([1, 2; 3, 4]); | |
138 %! assert((abs (l - [1, 0; 1/3, 1]) < sqrt (eps) | |
139 %! && abs (u - [3, 4; 0, 2/3]) < sqrt (eps) | |
140 %! && abs (p - [0, 1; 1, 0]) < sqrt (eps))); | |
141 | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
142 %!test |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
143 %! [l, u, p] = lu ([1, 2; 3, 4],'vector'); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
144 %! assert((abs (l - [1, 0; 1/3, 1]) < sqrt (eps) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
145 %! && abs (u - [3, 4; 0, 2/3]) < sqrt (eps) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
146 %! && abs (p - [2;1]) < sqrt (eps))); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
147 |
5590 | 148 %% test/octave.test/linalg/lu-4.m |
5751 | 149 %!error <Invalid call to lu.*> lu (); |
5590 | 150 |
151 %% test/octave.test/linalg/lu-5.m | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
152 %!error lu ([1, 2; 3, 4], 2); |
5590 | 153 |
154 %% test/octave.test/linalg/lu-6.m | |
155 %!test | |
156 %! [l u p] = lu ([1, 2; 3, 4; 5, 6]); | |
157 %! assert((abs (l - [1, 0; 1/5, 1; 3/5, 1/2]) < sqrt (eps) | |
158 %! && abs (u - [5, 6; 0, 4/5]) < sqrt (eps) | |
159 %! && abs (p - [0, 0, 1; 1, 0, 0; 0 1 0]) < sqrt (eps))); | |
160 | |
161 %% test/octave.test/linalg/qr-1.m | |
162 %!test | |
163 %! a = [0, 2, 1; 2, 1, 2]; | |
164 %! | |
165 %! [q, r] = qr (a); | |
166 %! | |
167 %! [qe, re] = qr (a, 0); | |
168 %! | |
169 %! assert((size (q) == [2, 2] && size (r) == [2, 3] | |
170 %! && abs (q * r - a) < sqrt (eps) | |
171 %! && size (qe) == [2, 2] && size (re) == [2, 3] | |
172 %! && abs (qe * re - a) < sqrt (eps))); | |
173 | |
174 %% test/octave.test/linalg/qr-2.m | |
175 %!test | |
176 %! a = [0, 2, 1; 2, 1, 2]; | |
177 %! | |
5775 | 178 %! [q, r, p] = qr (a); # not giving right dimensions. FIXME |
5590 | 179 %! |
180 %! [qe, re, pe] = qr (a, 0); | |
181 %! | |
182 %! assert((size (q) == [2, 2] && size (r) == [2, 3] && size (p) == [3, 3] | |
183 %! && abs (q * r - a * p) < sqrt (eps) | |
184 %! && size (qe) == [2, 2] && size (re) == [2, 3] && size (pe) == [1, 3] | |
185 %! && abs (qe * re - a(:,pe)) < sqrt (eps))); | |
186 | |
187 %% test/octave.test/linalg/qr-3.m | |
188 %!test | |
189 %! a = [0, 2; 2, 1; 1, 2]; | |
190 %! | |
191 %! [q, r] = qr (a); | |
192 %! | |
193 %! [qe, re] = qr (a, 0); | |
194 %! | |
195 %! assert((size (q) == [3, 3] && size (r) == [3, 2] | |
196 %! && abs (a - q * r) < sqrt (eps) | |
197 %! && size (qe) == [3, 2] && size (re) == [2, 2] | |
198 %! && abs (a - qe * re) < sqrt (eps))); | |
199 | |
200 %% test/octave.test/linalg/qr-4.m | |
201 %!test | |
202 %! a = [0, 2; 2, 1; 1, 2]; | |
203 %! | |
204 %! [q, r, p] = qr (a); | |
205 %! | |
206 %! [qe, re, pe] = qr (a, 0); | |
207 %! | |
208 %! assert((size (q) == [3, 3] && size (r) == [3, 2] && size (p) == [2, 2] | |
209 %! && abs (a * p - q * r) < sqrt (eps) | |
210 %! && size (qe) == [3, 2] && size (re) == [2, 2] && size (pe) == [1, 2] | |
211 %! && abs (a(:,pe) - qe * re) < sqrt (eps))); | |
212 | |
213 %% test/octave.test/linalg/qr-5.m | |
5751 | 214 %!error <Invalid call to qr.*> qr (); |
5590 | 215 |
216 %% test/octave.test/linalg/qr-6.m | |
5751 | 217 %!error <Invalid call to qr.*> qr ([1, 2; 3, 4], 0, 2); |
5590 | 218 |
219 %% test/octave.test/linalg/qr-7.m | |
220 %!function retval = testqr (q, r, a, p) | |
221 %! tol = 10*eps; | |
222 %! retval = 0; | |
223 %! if (nargin == 3) | |
224 %! n1 = norm (q*r-a); | |
225 %! n2 = norm (q'*q-eye(columns(q))); | |
226 %! retval = (n1 < tol && n2 < tol); | |
227 %! else | |
228 %! n1 = norm (q'*q-eye(columns(q))); | |
229 %! retval = (n1 < tol); | |
230 %! if (isvector (p)) | |
231 %! n2 = norm (q*r-a(:,p)); | |
232 %! retval = (retval && n2 < tol); | |
233 %! else | |
234 %! n2 = norm (q*r - a*p); | |
235 %! retval = (retval && n2 < tol); | |
236 %! endif | |
237 %! endif | |
238 %!test | |
239 %! | |
240 %! t = ones (24, 1); | |
241 %! j = 1; | |
242 %! | |
243 %! if 0 # eliminate big matrix tests | |
244 %! a = rand(5000,20); | |
245 %! [q,r]=qr(a,0); t(j++) = testqr(q,r,a); | |
246 %! [q,r]=qr(a',0); t(j++) = testqr(q,r,a'); | |
247 %! [q,r,p]=qr(a,0); t(j++) = testqr(q,r,a,p); | |
248 %! [q,r,p]=qr(a',0); t(j++) = testqr(q,r,a',p); | |
249 %! | |
250 %! a = a+1i*eps; | |
251 %! [q,r]=qr(a,0); t(j++) = testqr(q,r,a); | |
252 %! [q,r]=qr(a',0); t(j++) = testqr(q,r,a'); | |
253 %! [q,r,p]=qr(a,0); t(j++) = testqr(q,r,a,p); | |
254 %! [q,r,p]=qr(a',0); t(j++) = testqr(q,r,a',p); | |
255 %! endif | |
256 %! | |
257 %! a = [ ones(1,15); sqrt(eps)*eye(15) ]; | |
258 %! [q,r]=qr(a); t(j++) = testqr(q,r,a); | |
259 %! [q,r]=qr(a'); t(j++) = testqr(q,r,a'); | |
260 %! [q,r,p]=qr(a); t(j++) = testqr(q,r,a,p); | |
261 %! [q,r,p]=qr(a'); t(j++) = testqr(q,r,a',p); | |
262 %! | |
263 %! a = a+1i*eps; | |
264 %! [q,r]=qr(a); t(j++) = testqr(q,r,a); | |
265 %! [q,r]=qr(a'); t(j++) = testqr(q,r,a'); | |
266 %! [q,r,p]=qr(a); t(j++) = testqr(q,r,a,p); | |
267 %! [q,r,p]=qr(a'); t(j++) = testqr(q,r,a',p); | |
268 %! | |
269 %! a = [ ones(1,15); sqrt(eps)*eye(15) ]; | |
270 %! [q,r]=qr(a,0); t(j++) = testqr(q,r,a); | |
271 %! [q,r]=qr(a',0); t(j++) = testqr(q,r,a'); | |
272 %! [q,r,p]=qr(a,0); t(j++) = testqr(q,r,a,p); | |
273 %! [q,r,p]=qr(a',0); t(j++) = testqr(q,r,a',p); | |
274 %! | |
275 %! a = a+1i*eps; | |
276 %! [q,r]=qr(a,0); t(j++) = testqr(q,r,a); | |
277 %! [q,r]=qr(a',0); t(j++) = testqr(q,r,a'); | |
278 %! [q,r,p]=qr(a,0); t(j++) = testqr(q,r,a,p); | |
279 %! [q,r,p]=qr(a',0); t(j++) = testqr(q,r,a',p); | |
280 %! | |
281 %! a = [ | |
282 %! 611 196 -192 407 -8 -52 -49 29 | |
283 %! 196 899 113 -192 -71 -43 -8 -44 | |
284 %! -192 113 899 196 61 49 8 52 | |
285 %! 407 -192 196 611 8 44 59 -23 | |
286 %! -8 -71 61 8 411 -599 208 208 | |
287 %! -52 -43 49 44 -599 411 208 208 | |
288 %! -49 -8 8 59 208 208 99 -911 | |
289 %! 29 -44 52 -23 208 208 -911 99 | |
290 %! ]; | |
291 %! [q,r] = qr(a); | |
292 %! | |
293 %! assert(all (t) && norm(q*r-a) < 5000*eps); | |
294 | |
295 %% test/octave.test/linalg/schur-1.m | |
296 %!test | |
297 %! a = [1, 2, 3; 4, 5, 9; 7, 8, 6]; | |
298 %! [u, s] = schur (a); | |
299 %! assert(size (u) == [3, 3] && size (s) == [3, 3] && abs (s - u' * a * u) < sqrt (eps)); | |
300 | |
301 %% test/octave.test/linalg/schur-2.m | |
5751 | 302 %!error <Invalid call to schur.*> schur (); |
5590 | 303 |
304 %% test/octave.test/linalg/schur-3.m | |
305 %!test | |
306 %! warn_num_to_str = 1; | |
307 %! fail("schur ([1, 2; 3, 4], 2)","warning"); | |
308 | |
309 %% test/octave.test/linalg/schur-4.m | |
310 %!error schur ([1, 2, 3; 4, 5, 6]); | |
311 | |
312 %% test/octave.test/linalg/svd-1.m | |
313 %!assert(all (abs (svd ([1, 2; 2, 1]) - [3; 1]) < sqrt (eps))); | |
314 | |
315 %% test/octave.test/linalg/svd-2.m | |
316 %!test | |
317 %! [u, s, v] = svd ([1, 2; 2, 1]); | |
318 %! x = 1 / sqrt (2); | |
319 %! assert(((abs (u - [-x, -x; -x, x]) < sqrt (eps)) | |
320 %! && (abs (s - [3, 0; 0, 1]) < sqrt (eps)) | |
321 %! && (abs (v - [-x, x; -x, -x]) < sqrt (eps)))); | |
322 | |
323 %% test/octave.test/linalg/svd-3.m | |
324 %!test | |
325 %! a = [1, 2, 3; 4, 5, 6]; | |
326 %! [u, s, v] = svd (a); | |
327 %! assert((size (u) == [2, 2] && size (s) == [2, 3] && size (v) == [3, 3] | |
328 %! && abs (a - u * s * v') < sqrt (eps))); | |
329 | |
330 %% test/octave.test/linalg/svd-4.m | |
331 %!test | |
332 %! a = [1, 2; 3, 4; 5, 6]; | |
333 %! [u, s, v] = svd (a); | |
334 %! assert((size (u) == [3, 3] && size (s) == [3, 2] && size (v) == [2, 2] | |
335 %! && abs (a - u * s * v') < sqrt (eps))); | |
336 | |
337 %% test/octave.test/linalg/svd-5.m | |
338 %!test | |
339 %! a = [1, 2, 3; 4, 5, 6]; | |
340 %! [u, s, v] = svd (a, 1); | |
341 %! assert((size (u) == [2, 2] && size (s) == [2, 2] && size (v) == [3, 2] | |
342 %! && abs (a - u * s * v') < sqrt (eps))); | |
343 | |
344 %% test/octave.test/linalg/svd-6.m | |
345 %!test | |
346 %! a = [1, 2; 3, 4; 5, 6]; | |
347 %! [u, s, v] = svd (a, 1); | |
348 %! assert((size (u) == [3, 2] && size (s) == [2, 2] && size (v) == [2, 2] | |
349 %! && abs (a - u * s * v') < sqrt (eps))); | |
350 | |
351 %% test/octave.test/linalg/svd-7.m | |
5751 | 352 %!error <Invalid call to svd.*> svd (); |
5590 | 353 |
354 %% test/octave.test/linalg/svd-8.m | |
5751 | 355 %!error <Invalid call to svd.*> svd ([1, 2; 4, 5], 2, 3); |
5590 | 356 |
357 %% test/octave.test/linalg/svd-9.m | |
5751 | 358 %!error <Invalid call to svd.*> [u, v] = svd ([1, 2; 3, 4]); |
5590 | 359 |
360 %% test/octave.test/linalg/syl-1.m | |
361 %!test | |
362 %! x = syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12]); | |
363 %! assert(all (all (abs (x - [-1/2, -2/3; -2/3, -1/2]) < sqrt (eps)))); | |
364 | |
365 %% test/octave.test/linalg/syl-2.m | |
5751 | 366 %!error <Invalid call to syl.*> syl (); |
5590 | 367 |
368 %% test/octave.test/linalg/syl-3.m | |
5751 | 369 %!error <Invalid call to syl.*> syl (1, 2, 3, 4); |
5590 | 370 |
371 %% test/octave.test/linalg/syl-4.m | |
372 %!error syl ([1, 2; 3, 4], [1, 2, 3; 4, 5, 6], [4, 3]); | |
373 |