Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/newmat/tmt7.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: 4.1 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
18void trymat7()
19{
20//   cout << "\nSeventh test of Matrix package\n";
21   Tracer et("Seventh test of Matrix package");
22   Tracer::PrintTrace();
23
24   int i,j;
25
26
27   DiagonalMatrix D(6);
28   UpperTriangularMatrix U(6);
29   for (i=1;i<=6;i++) { for (j=i;j<=6;j++) U(i,j)=i*i*j-50; D(i,i)=i*i+i-10; }
30   LowerTriangularMatrix L=(U*3.0).t();
31   SymmetricMatrix S(6);
32   for (i=1;i<=6;i++) for (j=i;j<=6;j++) S(i,j)=i*i+2.0+j;
33   Matrix MD=D; Matrix ML=L; Matrix MU=U;
34   Matrix MS=S;
35   Matrix M(6,6);
36   for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; 
37   {
38      Tracer et1("Stage 1");
39      Print(Matrix((S-M)-(MS-M)));
40      Print(Matrix((-M-S)+(MS+M)));
41      Print(Matrix((U-M)-(MU-M)));
42   }
43   {
44      Tracer et1("Stage 2");
45      Print(Matrix((L-M)+(M-ML)));
46      Print(Matrix((D-M)+(M-MD)));
47      Print(Matrix((D-S)+(MS-MD)));
48      Print(Matrix((D-L)+(ML-MD)));
49   }
50
51   { M=MU.t(); }
52   LowerTriangularMatrix LY=D.i()*U.t();
53   {
54      Tracer et1("Stage 3");
55      MS=D*LY-M; Clean(MS,0.00000001); Print(MS);
56      L=U.t();
57      LY=D.i()*L; MS=D*LY-M; Clean(MS,0.00000001); Print(MS);
58   }
59   {
60      Tracer et1("Stage 4");
61      UpperTriangularMatrix UT(11);
62      int i, j;
63      for (i=1;i<=11;i++) for (j=i;j<=11;j++) UT(i,j)=i*i+j*3;
64      GenericMatrix GM; Matrix X;
65      UpperBandMatrix UB(11,3); UB.Inject(UT); UT = UB;
66      UpperBandMatrix UB2 = UB / 8;
67      GM = UB2-UT/8; X = GM; Print(X);
68      SymmetricBandMatrix SB(11,4); SB << (UB + UB.t());
69      X = SB - UT - UT.t(); Print(X);
70      BandMatrix B = UB + UB.t()*2;
71      DiagonalMatrix D; D << B;
72      X.ReSize(1,1); X(1,1) = Trace(B)-Sum(D); Print(X);
73      X = SB + 5; Matrix X1=X; X = SP(UB,X); Matrix X2 =UB;
74      X1 = (X1.AsDiagonal() * X2.AsDiagonal()).AsRow()-X.AsColumn().t();
75      Print(X1);
76      X1=SB.t(); X2 = B.t(); X = SB.i() * B - X1.i() * X2.t();
77      Clean(X,0.00000001); Print(X);
78      X = SB.i(); X = X * B - X1.i() * X2.t();
79      Clean(X,0.00000001); Print(X);
80      D = 1; X = SB.i() * SB - D; Clean(X,0.00000001); Print(X);
81      ColumnVector CV(11);
82      CV << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75;
83      D << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75;
84      X = CV.AsDiagonal(); X = X-D; Print(X);
85      SymmetricBandMatrix SB1(11,7); SB1 = 5; 
86      SymmetricBandMatrix SB2 = SB1 + D;
87      X.ReSize(11,11); X=0;
88      for (i=1;i<=11;i++) for (j=1;j<=11;j++)
89      {
90         if (abs(i-j)<=7) X(i,j)=5;
91         if (i==j) X(i,j)+=CV(i);
92      }
93      SymmetricMatrix SM; SM.ReSize(11);
94      SM=SB; SB = SB+SB2; X1 = SM+X-SB; Print(X1);
95      SB2=0; X2=SB2; X1=SB; Print(X2);
96      for (i=1;i<=11;i++) SB2.Column(i)<<SB.Column(i);
97      X1=X1-SB2; Print(X1);
98      X = SB; SB2.ReSize(11,4); SB2 = SB*5; SB2 = SB + SB2;
99      X1 = X*6 - SB2; Print(X1);
100      X1 = SP(SB,SB2/3); X1=X1-SP(X,X*2); Print(X1);
101      X1 = SP(SB2/6,X*2); X1=X1-SP(X*2,X); Print(X1);
102   }
103
104   {
105      // test the simple integer array class
106      Tracer et("Stage 5");
107      ColumnVector Test(10); Test = 0.0;
108      int i;
109      SimpleIntArray A(100);
110      for (i = 0; i < 100; i++) A[i] = i*i+1;
111      SimpleIntArray B(100), C(50), D(0);
112      D.ReSize(150);
113      B = A; A.ReSize(50, true); C = A; A.ReSize(150, true); D = A;
114      for (i = 0; i < 100; i++) if (B[i] != i*i+1) Test(1)=1;
115      for (i = 0; i < 50; i++) if (C[i] != i*i+1) Test(2)=1;
116      for (i = 0; i < 50; i++) if (D[i] != i*i+1) Test(3)=1;
117      A.ReSize(75); A = A.Size();
118      for (i = 0; i < 75; i++) if (A[i] != 75) Test(4)=1;
119      A.ReSize(25); A = A.Size();
120      for (i = 0; i < 25; i++) if (A[i] != 25) Test(5)=1;
121      A.ReSize(25); A = 23;
122      for (i = 0; i < 25; i++) if (A[i] != 23) Test(6)=1;
123      A.ReSize(0); A.ReSize(15); A = A.Size();
124      for (i = 0; i < 15; i++) if (A[i] != 15) Test(7)=1;
125      const SimpleIntArray E = B;
126      for (i = 0; i < 100; i++) if (E[i] != i*i+1) Test(8)=1;
127      Print(Test);
128   }
129
130
131//   cout << "\nEnd of seventh test\n";
132}
Note: See TracBrowser for help on using the repository browser.