18 using namespace NEWMAT;
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; }
26 #ifdef SETUP_C_SUBSCRIPTS 30 Tracer et(
"Twentieth test of Matrix package");
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++)
44 X.
element(i,j) = A.element(i,j) - B[i][j];
48 A.CleanUp(); B.CleanUp();
50 cout <<
"UpperTriangularMatrix\n";
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++)
57 X.
element(i,j) = A1.element(i,j) - B1[i][j];
61 A1.CleanUp(); B1.CleanUp();
63 cout <<
"LowerTriangularMatrix\n";
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++)
70 X.
element(i,j) = A2.element(i,j) - B2[i][j];
74 A2.CleanUp(); B2.CleanUp();
76 cout <<
"SymmetricMatrix\n";
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++)
83 X.
element(i,j) = A3.element(i,j) - B3[i][j];
87 A3.CleanUp(); B3.CleanUp();
89 cout <<
"DiagonalMatrix\n";
92 { A4[i] = i+100; B4(i+1) = i+100; }
93 X = A4 - B4;
Print(X); Y = X;
96 X.
element(i,i) = A4.element(i) - B4[i];
100 A4.CleanUp(); B4.CleanUp();
102 cout <<
"RowVector\n";
105 { A5[i] = i+100; B5(i+1) = i+100; }
106 X = A5 - B5;
Print(X); Y = X;
109 X.
element(0,i) = A5.element(i) - B5[i];
113 A5.CleanUp(); B5.CleanUp();
115 cout <<
"ColumnVector\n";
118 { A6[i] = i+100; B6(i+1) = i+100; }
119 X = A6 - B6;
Print(X); Y = X;
122 X.
element(i,0) = A6.element(i) - B6[i];
126 A6.CleanUp(); B6.CleanUp();
128 cout <<
"BandMatrix\n";
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++)
135 X.
element(i,j) = A7.element(i,j) - B7[i][j];
139 A7.CleanUp(); B7.CleanUp();
141 cout <<
"UpperBandMatrix\n";
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++)
148 X.
element(i,j) = A8.element(i,j) - B8[i][j];
152 A8.CleanUp(); B8.CleanUp();
154 cout <<
"LowerBandMatrix\n";
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++)
161 X.
element(i,j) = A9.element(i,j) - B9[i][j];
165 A9.CleanUp(); B9.CleanUp();
167 cout <<
"SymmetricBandMatrix\n";
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++)
174 X.
element(i,j) = Aa.element(i,j) - Ba[i][j];
178 Aa.CleanUp(); Ba.CleanUp();
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 };
199 Tracer et(
"Twentieth test of Matrix package");
202 cout <<
"C subscripts not enabled, not tested\n\n";
Upper triangular band matrix.
RowedMatrix AsRow() const
The usual rectangular matrix.
FloatVector FloatVector * a
static int my_max(int x, int y)
MatedMatrix AsMatrix(int m, int n) const
Lower triangular band matrix.
void Print(const Matrix &X)
static int my_min(int x, int y)