Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/newmat/tmt5.cpp @ 4565

Last change on this file since 4565 was 4565, checked in by patrick, 19 years ago

orxonox/trunk: added the newmat library to the project. needs some translation in directory, temp under util/newmat. is needed by the collision detection engine to perform lin alg operations such as eigenvector decomposition. perhaps we will make our own library to do that later.

File size: 3.4 KB
Line 
1
2//#define WANT_STREAM
3
4#include "include.h"
5
6#include "newmat.h"
7
8#include "tmt.h"
9
10#ifdef use_namespace
11using namespace NEWMAT;
12#endif
13
14
15// **************************** test program ******************************
16
17
18
19ReturnMatrix Returner0(const GenericMatrix& GM)
20{ Matrix M = GM; M.Release(); return M; }
21
22ReturnMatrix Returner1(const GenericMatrix& GM)
23{ Matrix M = GM+1; M.Release(); return M; }
24
25ReturnMatrix Returner2(const GenericMatrix& GM)
26{ UpperBandMatrix M = GM*2; M.Release(); return M; }
27
28ReturnMatrix Returner3(const GenericMatrix& GM)
29{ LowerBandMatrix M = GM*3; M.Release(); return M; }
30
31ReturnMatrix Returner4(const GenericMatrix& GM)
32{ SymmetricMatrix M = GM+4; M.Release(); return M; }
33
34ReturnMatrix Returner5(const GenericMatrix& GM)
35{ SymmetricBandMatrix M = GM*5; M.Release(); return M; }
36
37ReturnMatrix Returner6(const GenericMatrix& GM)
38{ BandMatrix M = GM*6; M.Release(); return M; }
39
40ReturnMatrix Returner7(const GenericMatrix& GM)
41{ DiagonalMatrix M = GM*7; M.Release(); return M; }
42
43void trymat5()
44{
45//   cout << "\nFifth test of Matrix package\n";
46   Tracer et("Fifth test of Matrix package");
47   Tracer::PrintTrace();
48
49   int i,j;
50
51   Matrix A(5,6);
52   for (i=1;i<=5;i++) for (j=1;j<=6;j++) A(i,j)=1+i*j+i*i+j*j;
53   ColumnVector CV(6);
54   for (i=1;i<=6;i++) CV(i)=i*i+3;
55   ColumnVector CV2(5); for (i=1;i<=5;i++) CV2(i)=1.0;
56   ColumnVector CV1=CV;
57
58   {
59      CV=A*CV;
60      RowVector RV=CV.t(); // RowVector RV; RV=CV.t();
61      RV=RV-1.0;
62      CV=(RV*A).t()+A.t()*CV2; CV1=(A.t()*A)*CV1 - CV;
63      Print(CV1);
64   }
65
66   CV1.ReSize(6);
67   CV2.ReSize(6);
68   CV.ReSize(6);
69   for (i=1;i<=6;i++) { CV1(i)=i*3+1; CV2(i)=10-i; CV(i)=11+i*2; }
70   ColumnVector CX=CV2-CV; { CX=CX+CV1; Print(CX); }
71   Print(ColumnVector(CV1+CV2-CV));
72   RowVector RV=CV.t(); RowVector RV1=CV1.t();
73   RowVector R=RV-RV1; Print(RowVector(R-CV2.t()));
74
75// test loading of list
76
77   RV.ReSize(10);
78   for (i=1;i<=10;i++) RV(i) = i*i;
79   RV1.ReSize(10);
80   RV1 << 1 << 4 << 9 << 16 << 25 << 36 << 49 << 64 << 81 << 100; // << 121;
81   Print(RowVector(RV-RV1));
82
83   et.ReName("Fifth test of Matrix package - almost at end");
84
85   Matrix X(2,3);
86   X << 11 << 12 << 13
87     << 21 << 22 << 23;
88
89   Matrix Y = X.t();                 // check simple transpose
90
91   X(1,1) -= 11; X(1,2) -= 12; X(1,3) -= 13;
92   X(2,1) -= 21; X(2,2) -= 22; X(2,3) -= 23;
93   Print(X);
94
95   Y(1,1) -= 11; Y(2,1) -= 12; Y(3,1) -= 13;
96   Y(1,2) -= 21; Y(2,2) -= 22; Y(3,2) -= 23;
97   Print(Y);
98
99   et.ReName("Fifth test of Matrix package - at end");
100
101   RV = Returner1(RV)-1; Print(RowVector(RV-RV1));
102   CV1 = Returner1(RV.t())-1; Print(ColumnVector(RV.t()-CV1));
103#ifndef DONT_DO_NRIC
104   nricMatrix AA = A;
105   X = Returner1(AA)-A-1; Print(X);
106#endif
107   UpperTriangularMatrix UT(31);
108   for (i=1; i<=31; i++) for (j=i; j<=31; j++) UT(i,j) = i+j+(i-j)*(i-2*j);
109   UpperBandMatrix UB(31,5); UB.Inject(UT);
110   LowerTriangularMatrix LT = UT.t();
111   LowerBandMatrix LB(31,5); LB.Inject(LT);
112   A = Returner0(UB)-LB.t(); Print(A);
113   A = Returner2(UB).t()-LB*2; Print(A);
114   A = Returner3(LB).t()-UB*3; Print(A);
115   SymmetricMatrix SM; SM << (UT+LT);
116   A = Returner4(SM)-UT-LT-4; Print(A);
117   SymmetricBandMatrix SB(31,5); SB.Inject(SM);
118   A = Returner5(SB)/5-UB-LB; Print(A);
119   BandMatrix B = UB+LB*LB; A = LB;
120   A = Returner6(B)/6 - UB - A*A; Print(A);
121   DiagonalMatrix D; D << UT;
122   D << (Returner7(D)/7 - UT); Print(D);
123
124//   cout << "\nEnd of fifth test\n";
125}
Note: See TracBrowser for help on using the repository browser.