lilypond-1.3.141
[lilypond.git] / flowertest / mat-test.cc
blob1ad7af49cebbfdb99ee03ba07f19ca260df2aa3c
1 /*
2 mat-test.cc -- test Matrix
4 source file of the Flower Library
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include <iostream.h>
10 #include "matrix.hh"
11 #include "string.hh"
12 #include "flower-test.hh"
13 #include "choleski.hh"
15 void
16 matrix()
18 int N=10;
19 Matrix m(N,N), q(N,N);
20 Vector v(N);
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;
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();
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);
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();
64 ADD_TEST(matrix);