1 | |
---|
2 | #define WANT_STREAM |
---|
3 | |
---|
4 | #include "include.h" |
---|
5 | |
---|
6 | #include "newmatap.h" |
---|
7 | #include "newmatio.h" |
---|
8 | |
---|
9 | #include "tmt.h" |
---|
10 | |
---|
11 | #ifdef use_namespace |
---|
12 | using namespace NEWMAT; |
---|
13 | #endif |
---|
14 | |
---|
15 | |
---|
16 | static inline int my_min(int x, int y) { return x < y ? x : y; } |
---|
17 | static inline int my_max(int x, int y) { return x > y ? x : y; } |
---|
18 | |
---|
19 | |
---|
20 | #ifdef SETUP_C_SUBSCRIPTS |
---|
21 | |
---|
22 | void trymatk() |
---|
23 | { |
---|
24 | Tracer et("Twentieth test of Matrix package"); |
---|
25 | Tracer::PrintTrace(); |
---|
26 | // test C subscript package |
---|
27 | |
---|
28 | |
---|
29 | int i,j; Matrix X, Y; |
---|
30 | |
---|
31 | cout << "Matrix\n"; |
---|
32 | Matrix A(15,35), B(15, 35); |
---|
33 | for (i=0; i<15; i++) for (j=0; j<35; j++) |
---|
34 | { A[i][j] = i+100*j; B(i+1,j+1) = i+100*j; } |
---|
35 | X = A - B; Print(X); Y = X; |
---|
36 | for (i=0; i<15; i++) for (j=0; j<35; j++) |
---|
37 | { |
---|
38 | X.element(i,j) = A.element(i,j) - B[i][j]; |
---|
39 | Y.element(i,j) = ((const Matrix&)A)[i][j] - B[i][j]; |
---|
40 | } |
---|
41 | Print(X); Print(Y); |
---|
42 | A.CleanUp(); B.CleanUp(); |
---|
43 | |
---|
44 | cout << "UpperTriangularMatrix\n"; |
---|
45 | UpperTriangularMatrix A1(15), B1(15); |
---|
46 | for (i=0; i<15; i++) for (j=i; j<15; j++) |
---|
47 | { A1[i][j] = i+100*j; B1(i+1,j+1) = i+100*j; } |
---|
48 | X = A1 - B1; Print(X); Y = X; |
---|
49 | for (i=0; i<15; i++) for (j=i; j<15; j++) |
---|
50 | { |
---|
51 | X.element(i,j) = A1.element(i,j) - B1[i][j]; |
---|
52 | Y.element(i,j) = ((const UpperTriangularMatrix&)A1)[i][j] - B1[i][j]; |
---|
53 | } |
---|
54 | Print(X); Print(Y); |
---|
55 | A1.CleanUp(); B1.CleanUp(); |
---|
56 | |
---|
57 | cout << "LowerTriangularMatrix\n"; |
---|
58 | LowerTriangularMatrix A2(35), B2(35); |
---|
59 | for (i=0; i<35; i++) for (j=0; j<=i; j++) |
---|
60 | { A2[i][j] = i+100*j; B2(i+1,j+1) = i+100*j; } |
---|
61 | X = A2 - B2; Print(X); Y = X; |
---|
62 | for (i=0; i<35; i++) for (j=0; j<=i; j++) |
---|
63 | { |
---|
64 | X.element(i,j) = A2.element(i,j) - B2[i][j]; |
---|
65 | Y.element(i,j) = ((const LowerTriangularMatrix&)A2)[i][j] - B2[i][j]; |
---|
66 | } |
---|
67 | Print(X); Print(Y); |
---|
68 | A2.CleanUp(); B2.CleanUp(); |
---|
69 | |
---|
70 | cout << "SymmetricMatrix\n"; |
---|
71 | SymmetricMatrix A3(10), B3(10); |
---|
72 | for (i=0; i<10; i++) for (j=0; j<=i; j++) |
---|
73 | { A3[i][j] = i+100*j; B3(i+1,j+1) = i+100*j; } |
---|
74 | X = A3 - B3; Print(X); Y = X; |
---|
75 | for (i=0; i<10; i++) for (j=0; j<=i; j++) |
---|
76 | { |
---|
77 | X.element(i,j) = A3.element(i,j) - B3[i][j]; |
---|
78 | Y.element(i,j) = ((const SymmetricMatrix&)A3)[i][j] - B3[i][j]; |
---|
79 | } |
---|
80 | Print(X); Print(Y); |
---|
81 | A3.CleanUp(); B3.CleanUp(); |
---|
82 | |
---|
83 | cout << "DiagonalMatrix\n"; |
---|
84 | DiagonalMatrix A4(10), B4(10); |
---|
85 | for (i=0; i<10; i++) |
---|
86 | { A4[i] = i+100; B4(i+1) = i+100; } |
---|
87 | X = A4 - B4; Print(X); Y = X; |
---|
88 | for (i=0; i<10; i++) |
---|
89 | { |
---|
90 | X.element(i,i) = A4.element(i) - B4[i]; |
---|
91 | Y.element(i,i) = ((const DiagonalMatrix&)A4)[i] - B4[i]; |
---|
92 | } |
---|
93 | Print(X); Print(Y); |
---|
94 | A4.CleanUp(); B4.CleanUp(); |
---|
95 | |
---|
96 | cout << "RowVector\n"; |
---|
97 | RowVector A5(10), B5(10); |
---|
98 | for (i=0; i<10; i++) |
---|
99 | { A5[i] = i+100; B5(i+1) = i+100; } |
---|
100 | X = A5 - B5; Print(X); Y = X; |
---|
101 | for (i=0; i<10; i++) |
---|
102 | { |
---|
103 | X.element(0,i) = A5.element(i) - B5[i]; |
---|
104 | Y.element(0,i) = ((const RowVector&)A5)[i] - B5[i]; |
---|
105 | } |
---|
106 | Print(X); Print(Y); |
---|
107 | A5.CleanUp(); B5.CleanUp(); |
---|
108 | |
---|
109 | cout << "ColumnVector\n"; |
---|
110 | ColumnVector A6(10), B6(10); |
---|
111 | for (i=0; i<10; i++) |
---|
112 | { A6[i] = i+100; B6(i+1) = i+100; } |
---|
113 | X = A6 - B6; Print(X); Y = X; |
---|
114 | for (i=0; i<10; i++) |
---|
115 | { |
---|
116 | X.element(i,0) = A6.element(i) - B6[i]; |
---|
117 | Y.element(i,0) = ((const ColumnVector&)A6)[i] - B6[i]; |
---|
118 | } |
---|
119 | Print(X); Print(Y); |
---|
120 | A6.CleanUp(); B6.CleanUp(); |
---|
121 | |
---|
122 | cout << "BandMatrix\n"; |
---|
123 | BandMatrix A7(55,10, 5), B7(55, 10, 5); |
---|
124 | for (i=0; i<55; i++) for (j=my_max(0,i-10); j<=my_min(54,i+5); j++) |
---|
125 | { A7[i][j] = i+100*j; B7(i+1,j+1) = i+100*j; } |
---|
126 | X = A7 - B7; Print(X); Y = X; |
---|
127 | for (i=0; i<55; i++) for (j=my_max(0,i-10); j<=my_min(54,i+5); j++) |
---|
128 | { |
---|
129 | X.element(i,j) = A7.element(i,j) - B7[i][j]; |
---|
130 | Y.element(i,j) = ((const BandMatrix&)A7)[i][j] - B7[i][j]; |
---|
131 | } |
---|
132 | Print(X); Print(Y); |
---|
133 | A7.CleanUp(); B7.CleanUp(); |
---|
134 | |
---|
135 | cout << "UpperBandMatrix\n"; |
---|
136 | UpperBandMatrix A8(80,15), B8(80,15); |
---|
137 | for (i=0; i<80; i++) for (j=i; j<=my_min(79,i+15); j++) |
---|
138 | { A8[i][j] = i+100*j; B8(i+1,j+1) = i+100*j; } |
---|
139 | X = A8 - B8; Print(X); Y = X; |
---|
140 | for (i=0; i<80; i++) for (j=i; j<=my_min(79,i+15); j++) |
---|
141 | { |
---|
142 | X.element(i,j) = A8.element(i,j) - B8[i][j]; |
---|
143 | Y.element(i,j) = ((const UpperBandMatrix&)A8)[i][j] - B8[i][j]; |
---|
144 | } |
---|
145 | Print(X); Print(Y); |
---|
146 | A8.CleanUp(); B8.CleanUp(); |
---|
147 | |
---|
148 | cout << "LowerBandMatrix\n"; |
---|
149 | LowerBandMatrix A9(75,27), B9(75,27); |
---|
150 | for (i=0; i<75; i++) for (j=my_max(0,i-27); j<=i; j++) |
---|
151 | { A9[i][j] = i+100*j; B9(i+1,j+1) = i+100*j; } |
---|
152 | X = A9 - B9; Print(X); Y = X; |
---|
153 | for (i=0; i<75; i++) for (j=my_max(0,i-27); j<=i; j++) |
---|
154 | { |
---|
155 | X.element(i,j) = A9.element(i,j) - B9[i][j]; |
---|
156 | Y.element(i,j) = ((const LowerBandMatrix&)A9)[i][j] - B9[i][j]; |
---|
157 | } |
---|
158 | Print(X); Print(Y); |
---|
159 | A9.CleanUp(); B9.CleanUp(); |
---|
160 | |
---|
161 | cout << "SymmetricBandMatrix\n"; |
---|
162 | SymmetricBandMatrix Aa(69,15), Ba(69,15); |
---|
163 | for (i=0; i<69; i++) for (j=my_max(0,i-15); j<=i; j++) |
---|
164 | { Aa[i][j] = i+100*j; Ba(i+1,j+1) = i+100*j; } |
---|
165 | X = Aa - Ba; Print(X); Y = X; |
---|
166 | for (i=0; i<69; i++) for (j=my_max(0,i-15); j<=i; j++) |
---|
167 | { |
---|
168 | X.element(i,j) = Aa.element(i,j) - Ba[i][j]; |
---|
169 | Y.element(i,j) = ((const SymmetricBandMatrix&)Aa)[i][j] - Ba[i][j]; |
---|
170 | } |
---|
171 | Print(X); Print(Y); |
---|
172 | Aa.CleanUp(); Ba.CleanUp(); |
---|
173 | |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | #else |
---|
179 | |
---|
180 | void trymatk() |
---|
181 | { |
---|
182 | Tracer et("Twentieth test of Matrix package"); |
---|
183 | Tracer::PrintTrace(); |
---|
184 | // test C subscript package |
---|
185 | cout << "C subscripts not enabled, not tested\n\n"; |
---|
186 | } |
---|
187 | |
---|
188 | #endif |
---|