]> git.donarmstrong.com Git - lilypond.git/blob - flower/test/mat-test.cc
release: 0.1.1
[lilypond.git] / flower / test / mat-test.cc
1 /*
2   mat-test.cc -- test Matrix
3
4   source file of the Flower Library
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <iostream.h>
10 #include "matrix.hh"
11 #include "string.hh"
12 #include "flower-test.hh"
13 #include "choleski.hh"
14
15 void
16 matrix()
17 {
18     int N=10;
19     Matrix m(N,N), q(N,N);
20     Vector v(N);
21
22     for (int i=0; i < N; i++) {
23         v(i) =i;
24         for (int j=0; j < N; j++) {
25             m(i,j) = i+j;
26             q(i,j) = (abs(i-j) > 3) ?0 :i-j;
27         }
28     }
29
30     cout << "v: " << String(v);
31     cout << "m: " <<  String(m );
32     cout << "q: " <<  String(q);
33     cout << "m*q; " <<  String(m*q);
34     cout << "m*m: " <<  String(m*m);
35     m.OK();
36     cout << "m: " <<  String(m);
37     cout << "q.band " << q.band_i() << endl; 
38     q.try_set_band();
39     cout << "q(B): " << q;
40     q.OK();
41     Matrix sum(q+q);
42     cout << "q + q " << sum;
43     q.OK();
44     cout << "q*q: " << q*q;
45     q.OK();
46
47     Matrix hilbert(N,N), h2(hilbert);
48     for (int i=0; i < N; i++) {
49         for (int j=0; j < N; j++) {
50             hilbert(i,j) = 1/Real(i+j+1);
51              h2 (i,j) = (abs(i-j) > 3) ?0 : hilbert(i,j);
52         }
53     }
54     h2.try_set_band();
55     Choleski_decomposition ch(h2);
56     cout << "red Hilbert  " <<  h2;
57     cout << "choleski " << ch.L;
58     Matrix T =ch.L.transposed();
59     cout << "L^T " <<  T;
60     cout << "L * L^T" << ch.L * T;
61     cout << "H2^{-1} * H2" << h2 * ch.inverse();
62 }
63
64 ADD_TEST(matrix);