source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/zisserman/vgg_numerics/vgg_matrix_test.m @ 86

Last change on this file since 86 was 37, checked in by (none), 15 years ago

Added original make3d

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1function vgg_matrix_test
2% Test the matrix "flattening" functions from Magnus and Neudecker
3%  vgg_vec
4%  vgg_vech
5%  vgg_commut_matrix
6%  vgg_duplic_matrix
7%  vgg_lmultiply_matrix
8
9% Author: awf@robots.ox.ac.uk
10
11A = randn(4,5);
12B = randn(5,2);
13C = randn(2,4);
14
15fprintf('vgg_matrix_test: BEGIN\n');
16assert('vgg_vec(A*B*C)', 'kron(C'',A)*vgg_vec(B)');
17assert('vgg_vec(A*B)', 'vgg_lmultiply_matrix(A,size(B))*vgg_vec(B)');
18assert('vgg_vec(B*C)', 'vgg_rmultiply_matrix(C,size(B))*vgg_vec(B)');
19
20
21% Now try to solve A X + X B = C:
22X_true = randn(4,4);
23A = randn(4,4);
24B = randn(4,4);
25C = A*X_true + X_true*B;
26
27% Re-express in terms of x = vec(X):
28% fA x + gB x  = vec(C)
29% so
30% x = (fA + gB) \ vec(C)
31size_X = [4 4]; % need to know size(X) to convert the matrix multiplys
32fA = vgg_lmultiply_matrix(A, size_X);
33gB = vgg_rmultiply_matrix(B, size_X);
34x = (fA + gB)\vgg_vec(C);
35
36% Now check we got it right...
37assert('x', 'vgg_vec(X_true)')
38
39
40
41fprintf('vgg_matrix_test: END\n');
42
43function assert(sx,sy)
44x = evalin('caller', sx);
45y = evalin('caller', sy);
46err = norm(x-y);
47if err > 1e-12
48  dbstack
49  fprintf('vgg_matrix_test: FAILED %s = %s\n', sx, sy);
50  keyboard
51else
52  fprintf('vgg_matrix_test: PASSED %s = %s\n', sx, sy);
53end
Note: See TracBrowser for help on using the repository browser.