tmtb.cpp
Go to the documentation of this file.
1 
6 
7 
8 //#define WANT_STREAM
9 
10 #include "include.h"
11 
12 #include "newmat.h"
13 
14 #include "tmt.h"
15 
16 #ifdef use_namespace
17 using namespace NEWMAT;
18 #endif
19 
20 
21 /**************************** test program ******************************/
22 
23 // make sure matrices work as members of a class
24 
25 class TestClass
26 {
29 public:
30  TestClass();
31  ReturnMatrix Sum();
32 };
33 
35 {
36  B.ReSize(2,3);
37  A << 1 << 4
38  << 4 << 1
39  << 2 << 9;
40  B << 8 << 5
41  << 5 << 8
42  << 7 << 0;
43 }
44 
46 
47 
48 
49 void trymatb()
50 {
51 // cout << "\nEleventh test of Matrix package\n";
52  Tracer et("Eleventh test of Matrix package");
54  int i; int j;
55  RowVector RV; RV.ReSize(10);
56  {
57  Tracer et1("Stage 1");
58  for (i=1;i<=10;i++) RV(i)=i*i-3;
59  Matrix X(1,1); X(1,1) = .25;
60  Print(RowVector(X.i() * RV - RV / .25));
61 // Print(RowVector(X.i() * Matrix(RV) - RV / .25)); // != zortech, AT&T
62  Print(RowVector(X.i() * RV - RV / .25));
63  }
65  for (i=1; i<=5; i++) for (j=1; j<=i; j++)
66  { L(i,j) = i*i + j -2.0; U(j,i) = i*i*j+3; }
67  DiagonalMatrix D(5);
68  for (i=1; i<=5; i++) D(i,i) = i*i + i + 2;
69  Matrix M1 = -L; Matrix M2 = L-U; Matrix M3 = U*3; Matrix M4 = U-L;
70  Matrix M5 = M1 - D; M1 = D * (-3) - M3;
71  {
72  Tracer et1("Stage 2");
73  Print(Matrix((M2-M4*2)+M5*3-M1));
74  M1 = L.t(); Print(Matrix(M1.t()-L));
75  M1 = U.t(); Print(Matrix(M1.t()-U));
76  }
77  {
78  Tracer et1("Stage 3");
79  SymmetricMatrix S(5);
80  for (i=1; i<=5; i++) for (j=1; j<=i; j++) S(i,j) = i*j+i-j+5;
81  M2 = S.i() * M4; M1 = S; M3=M1*M2-M4; Clean(M3,0.00000001); Print(M3);
82  SymmetricMatrix T(5);
83  for (i=1; i<=5; i++) for (j=1; j<=i; j++) T(i,j) = i*i*j*j+i-j+5-i*j;
84  M1 = S.i() * T; M1 = S * M1; M1 = M1-T; Clean(M1,0.00000001); Print(M1);
85  ColumnVector CV(5); for (i=1; i<=5; i++) CV(i) = i*i*i+10;
86  M1 = CV * RV;
87  }
88  {
89  Tracer et1("Stage 4");
90  M4.ReSize(5,10);
91  for (i=1; i<=5; i++) for (j=1; j<=10; j++) M4(i,j) = (i*i*i+10)*(j*j-3);
92  Print(Matrix(M1-M4));
93  M1 = L.t(); M2 = U.t(); M3 = L+U; Print(Matrix(M1-M3.t()+M2));
94  }
95 // UpperTriangularMatrix U2((const UpperTriangularMatrix&)U); // != zortech
97  {
98  Tracer et1("Stage 5");
99  Print(Matrix(U2-U));
100  M2.ReSize(10,10);
101  for (i=1; i<=10; i++) for (j=1; j<=10; j++) M2(i,j) = (i*i*i+10)*(j*j-3);
102  D << M2; L << M2; U << M2; // check copy into
103  Print( Matrix( (D+M2)-(L+U) ) );
104  }
105  {
106  Tracer et1("Stage 6");
107  M1.ReSize(6,10);
108  for (i=1; i<=6; i++) for (j=1; j<=10; j++) M1(i,j) = 100*i + j;
109  M2 = M1.SubMatrix(3,5,4,7); M3.ReSize(3,4);
110  for (i=3; i<=5; i++) for (j=4; j<=7; j++) M3(i-2,j-3) = 100*i + j;
111  Print(Matrix(M2-M3));
112  }
113  int a1,a2,a3,a4;
114  {
115  Tracer et1("Stage 7");
116  int a1,a2,a3,a4;
117  a1=4; a2=9; a3=4; a4=7;
118  U.ReSize(10);
119  for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
120  M2 = U.SubMatrix(a1,a2,a3,a4);
121  M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
122  for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
123  M3(i-a1+1,j-a3+1) = 100*i + j;
124  Print(Matrix(M2-M3));
125  }
126  {
127  Tracer et1("Stage 8");
128  a1=3; a2=9; a3=2; a4=7;
129  U.ReSize(10);
130  for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
131  M2 = U.SubMatrix(a1,a2,a3,a4);
132  M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
133  for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
134  M3(i-a1+1,j-a3+1) = 100*i + j;
135  Print(Matrix(M2-M3));
136  }
137  {
138  Tracer et1("Stage 9");
139  a1=4; a2=6; a3=2; a4=5;
140  U.ReSize(10);
141  for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
142  M2 = U.SubMatrix(a1,a2,a3,a4);
143  M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
144  for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
145  M3(i-a1+1,j-a3+1) = 100*i + j;
146  Print(Matrix(M2-M3));
147  }
148 
149  {
150  Tracer et1("Stage 10");
151  TestClass TC;
152  Matrix M = TC.Sum() - 9;
153  Print(M);
154  }
155 
156 
157 // cout << "\nEnd of eleventh test\n";
158 }
159 
160 
161 
TestClass()
Definition: tmtb.cpp:34
Real Sum(const BaseMatrix &B)
Definition: newmat.h:2107
virtual void ReSize(int m, int n)
Definition: newmat.h:662
void ReSize(int m)
Definition: newmat.h:985
Upper triangular matrix.
Definition: newmat.h:799
void Clean(Matrix &A, Real c)
Definition: tmt.cpp:128
Matrix A
Definition: tmtb.cpp:27
TransposedMatrix t() const
Definition: newmat6.cpp:320
ReturnMatrix Sum()
Definition: tmtb.cpp:45
static void PrintTrace()
Definition: myexcept.cpp:109
The usual rectangular matrix.
Definition: newmat.h:625
InvertedMatrix i() const
Definition: newmat6.cpp:329
void trymatb()
Definition: tmtb.cpp:49
Diagonal matrix.
Definition: newmat.h:896
Lower triangular matrix.
Definition: newmat.h:848
GetSubMatrix SubMatrix(int fr, int lr, int fc, int lc) const
Definition: newmat.h:2146
ReturnMatrix ForReturn() const
Definition: newmat.h:2157
Row vector.
Definition: newmat.h:953
void Print(const Matrix &X)
Definition: tmt.cpp:42
Column vector.
Definition: newmat.h:1008
Matrix B
Definition: tmtb.cpp:28
void ReSize(int m)
Definition: newmat.h:833
Symmetric matrix.
Definition: newmat.h:753


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:45