tmtk.cpp
Go to the documentation of this file.
1 
6 
7 
8 #define WANT_STREAM
9 
10 #include "include.h"
11 
12 #include "newmatap.h"
13 #include "newmatio.h"
14 
15 #include "tmt.h"
16 
17 #ifdef use_namespace
18 using namespace NEWMAT;
19 #endif
20 
21 
22 static inline int my_min(int x, int y) { return x < y ? x : y; }
23 static inline int my_max(int x, int y) { return x > y ? x : y; }
24 
25 
26 #ifdef SETUP_C_SUBSCRIPTS
27 
28 void trymatk()
29 {
30  Tracer et("Twentieth test of Matrix package");
32  // test C subscript package
33 
34 
35  int i,j; Matrix X, Y;
36 
37  cout << "Matrix\n";
38  Matrix A(15,35), B(15, 35);
39  for (i=0; i<15; i++) for (j=0; j<35; j++)
40  { A[i][j] = i+100*j; B(i+1,j+1) = i+100*j; }
41  X = A - B; Print(X); Y = X;
42  for (i=0; i<15; i++) for (j=0; j<35; j++)
43  {
44  X.element(i,j) = A.element(i,j) - B[i][j];
45  Y.element(i,j) = ((const Matrix&)A)[i][j] - B[i][j];
46  }
47  Print(X); Print(Y);
48  A.CleanUp(); B.CleanUp();
49 
50  cout << "UpperTriangularMatrix\n";
51  UpperTriangularMatrix A1(15), B1(15);
52  for (i=0; i<15; i++) for (j=i; j<15; j++)
53  { A1[i][j] = i+100*j; B1(i+1,j+1) = i+100*j; }
54  X = A1 - B1; Print(X); Y = X;
55  for (i=0; i<15; i++) for (j=i; j<15; j++)
56  {
57  X.element(i,j) = A1.element(i,j) - B1[i][j];
58  Y.element(i,j) = ((const UpperTriangularMatrix&)A1)[i][j] - B1[i][j];
59  }
60  Print(X); Print(Y);
61  A1.CleanUp(); B1.CleanUp();
62 
63  cout << "LowerTriangularMatrix\n";
64  LowerTriangularMatrix A2(35), B2(35);
65  for (i=0; i<35; i++) for (j=0; j<=i; j++)
66  { A2[i][j] = i+100*j; B2(i+1,j+1) = i+100*j; }
67  X = A2 - B2; Print(X); Y = X;
68  for (i=0; i<35; i++) for (j=0; j<=i; j++)
69  {
70  X.element(i,j) = A2.element(i,j) - B2[i][j];
71  Y.element(i,j) = ((const LowerTriangularMatrix&)A2)[i][j] - B2[i][j];
72  }
73  Print(X); Print(Y);
74  A2.CleanUp(); B2.CleanUp();
75 
76  cout << "SymmetricMatrix\n";
77  SymmetricMatrix A3(10), B3(10);
78  for (i=0; i<10; i++) for (j=0; j<=i; j++)
79  { A3[i][j] = i+100*j; B3(i+1,j+1) = i+100*j; }
80  X = A3 - B3; Print(X); Y = X;
81  for (i=0; i<10; i++) for (j=0; j<=i; j++)
82  {
83  X.element(i,j) = A3.element(i,j) - B3[i][j];
84  Y.element(i,j) = ((const SymmetricMatrix&)A3)[i][j] - B3[i][j];
85  }
86  Print(X); Print(Y);
87  A3.CleanUp(); B3.CleanUp();
88 
89  cout << "DiagonalMatrix\n";
90  DiagonalMatrix A4(10), B4(10);
91  for (i=0; i<10; i++)
92  { A4[i] = i+100; B4(i+1) = i+100; }
93  X = A4 - B4; Print(X); Y = X;
94  for (i=0; i<10; i++)
95  {
96  X.element(i,i) = A4.element(i) - B4[i];
97  Y.element(i,i) = ((const DiagonalMatrix&)A4)[i] - B4[i];
98  }
99  Print(X); Print(Y);
100  A4.CleanUp(); B4.CleanUp();
101 
102  cout << "RowVector\n";
103  RowVector A5(10), B5(10);
104  for (i=0; i<10; i++)
105  { A5[i] = i+100; B5(i+1) = i+100; }
106  X = A5 - B5; Print(X); Y = X;
107  for (i=0; i<10; i++)
108  {
109  X.element(0,i) = A5.element(i) - B5[i];
110  Y.element(0,i) = ((const RowVector&)A5)[i] - B5[i];
111  }
112  Print(X); Print(Y);
113  A5.CleanUp(); B5.CleanUp();
114 
115  cout << "ColumnVector\n";
116  ColumnVector A6(10), B6(10);
117  for (i=0; i<10; i++)
118  { A6[i] = i+100; B6(i+1) = i+100; }
119  X = A6 - B6; Print(X); Y = X;
120  for (i=0; i<10; i++)
121  {
122  X.element(i,0) = A6.element(i) - B6[i];
123  Y.element(i,0) = ((const ColumnVector&)A6)[i] - B6[i];
124  }
125  Print(X); Print(Y);
126  A6.CleanUp(); B6.CleanUp();
127 
128  cout << "BandMatrix\n";
129  BandMatrix A7(55,10, 5), B7(55, 10, 5);
130  for (i=0; i<55; i++) for (j=my_max(0,i-10); j<=my_min(54,i+5); j++)
131  { A7[i][j] = i+100*j; B7(i+1,j+1) = i+100*j; }
132  X = A7 - B7; Print(X); Y = X;
133  for (i=0; i<55; i++) for (j=my_max(0,i-10); j<=my_min(54,i+5); j++)
134  {
135  X.element(i,j) = A7.element(i,j) - B7[i][j];
136  Y.element(i,j) = ((const BandMatrix&)A7)[i][j] - B7[i][j];
137  }
138  Print(X); Print(Y);
139  A7.CleanUp(); B7.CleanUp();
140 
141  cout << "UpperBandMatrix\n";
142  UpperBandMatrix A8(80,15), B8(80,15);
143  for (i=0; i<80; i++) for (j=i; j<=my_min(79,i+15); j++)
144  { A8[i][j] = i+100*j; B8(i+1,j+1) = i+100*j; }
145  X = A8 - B8; Print(X); Y = X;
146  for (i=0; i<80; i++) for (j=i; j<=my_min(79,i+15); j++)
147  {
148  X.element(i,j) = A8.element(i,j) - B8[i][j];
149  Y.element(i,j) = ((const UpperBandMatrix&)A8)[i][j] - B8[i][j];
150  }
151  Print(X); Print(Y);
152  A8.CleanUp(); B8.CleanUp();
153 
154  cout << "LowerBandMatrix\n";
155  LowerBandMatrix A9(75,27), B9(75,27);
156  for (i=0; i<75; i++) for (j=my_max(0,i-27); j<=i; j++)
157  { A9[i][j] = i+100*j; B9(i+1,j+1) = i+100*j; }
158  X = A9 - B9; Print(X); Y = X;
159  for (i=0; i<75; i++) for (j=my_max(0,i-27); j<=i; j++)
160  {
161  X.element(i,j) = A9.element(i,j) - B9[i][j];
162  Y.element(i,j) = ((const LowerBandMatrix&)A9)[i][j] - B9[i][j];
163  }
164  Print(X); Print(Y);
165  A9.CleanUp(); B9.CleanUp();
166 
167  cout << "SymmetricBandMatrix\n";
168  SymmetricBandMatrix Aa(69,15), Ba(69,15);
169  for (i=0; i<69; i++) for (j=my_max(0,i-15); j<=i; j++)
170  { Aa[i][j] = i+100*j; Ba(i+1,j+1) = i+100*j; }
171  X = Aa - Ba; Print(X); Y = X;
172  for (i=0; i<69; i++) for (j=my_max(0,i-15); j<=i; j++)
173  {
174  X.element(i,j) = Aa.element(i,j) - Ba[i][j];
175  Y.element(i,j) = ((const SymmetricBandMatrix&)Aa)[i][j] - Ba[i][j];
176  }
177  Print(X); Print(Y);
178  Aa.CleanUp(); Ba.CleanUp();
179 
180  // test special constructors used in Numerical Recipes for C++
181  Real a[] = {1.2, 5.6, 7.9, 3.8, 4.5, 1.3,
182  5.2, 9.9, 2.1, 4.7, 0.0, 1.6 };
183  ColumnVector CV0(12); CV0 << a;
184  ColumnVector CV1(a, 12); CV1 -= CV0; Print(CV1);
185  RowVector RV1(a, 12); RV1 -= CV0.AsRow(); Print(RV1);
186  Matrix RM1(a, 3, 4); RM1 -= CV0.AsMatrix(3,4); Print(RM1);
187  ColumnVector CV2(5.75, 15); CV2 -= 5.75; Print(CV2);
188  RowVector RV2(2.75, 15); RV2 -= 2.75; Print(RV2);
189  Matrix RM2(-3.75, 6, 4); RM2 += 3.75; Print(RM2);
190 
191 
192 }
193 
194 
195 #else
196 
197 void trymatk()
198 {
199  Tracer et("Twentieth test of Matrix package");
201  // test C subscript package
202  cout << "C subscripts not enabled, not tested\n\n";
203 }
204 
205 #endif
206 
207 
void trymatk()
Definition: tmtk.cpp:197
double Real
Definition: include.h:307
Real & element(int, int)
Definition: newmat6.cpp:682
Upper triangular band matrix.
Definition: newmat.h:1167
Upper triangular matrix.
Definition: newmat.h:799
RowedMatrix AsRow() const
Definition: newmat.h:2141
Band matrix.
Definition: newmat.h:1096
static void PrintTrace()
Definition: myexcept.cpp:109
The usual rectangular matrix.
Definition: newmat.h:625
FloatVector FloatVector * a
static int my_max(int x, int y)
Definition: tmtk.cpp:23
MatedMatrix AsMatrix(int m, int n) const
Definition: newmat.h:2144
Diagonal matrix.
Definition: newmat.h:896
Lower triangular matrix.
Definition: newmat.h:848
Symmetric band matrix.
Definition: newmat.h:1245
Lower triangular band matrix.
Definition: newmat.h:1206
Row vector.
Definition: newmat.h:953
void Print(const Matrix &X)
Definition: tmt.cpp:42
Column vector.
Definition: newmat.h:1008
static int my_min(int x, int y)
Definition: tmtk.cpp:22
Symmetric matrix.
Definition: newmat.h:753


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:17