17 using namespace NEWMAT;
35 for (i = 1; i <=
m; i++)
for (j = 1; j <= n; j++)
36 dcr[i][j] = d[i] * c[i] * r[j];
44 Tracer et(
"Eighth test of Matrix package");
51 for (i=1;i<=6;i++) D(i,i)=i*i+i-10;
65 DX=-DX*DX+(DX-(-D1))*((-D1)+DX);
85 LT << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
90 GM2 = GM1; LT1 = GM2; LT1 = LT1-LT;
Print(LT1);
91 GM2 = GM1*2; LT1 = GM2; LT1 = LT1-LT*2;
Print(LT1);
93 GM1=GM1; LT1=GM1-LT;
Print(LT1); LT1=GM1-LT;
Print(LT1);
95 GM1=GM1*4; LT1=GM1-LT*4;
Print(LT1);
97 GM1=LT; GM2=UT; GM1=GM1*GM2;
Matrix M=GM1; M=M-LT*UT;
Print(M);
100 GM1 = LT; GM1 = GM1 + GM1; LT1 = LT*2-GM1;
Print(LT1);
108 M(1,1) = M(2,2) = M(4,4) = M(6,6) =
109 M(7,7) = M(8,8) = M(10,10) = M(12,12) = -1;
110 M(1,6) = M(1,12) = -5.601594;
111 M(3,6) = M(3,12) = -0.000165;
112 M(7,6) = M(7,12) = -0.008294;
119 DX(2) = DX(3) = DX(4) = DX(5) = DX(6) = DX(7) = 1;
121 DX(9) = DX(10) = DX(11) = DX(12) = 0;
129 D << 1 << 4 << 6 << 2 << 1 << 6 << 4 << 7 << 3 << 1;
131 C << 3 << 7 << 5 << 1 << 4 << 2 << 3 << 9 << 1 << 3;
133 R << 2 << 3 << 5 << 7 << 11 << 13;
136 M -= D * C * R;
Print(M);
139 D << 1.25 << 4.75 << 9.5 << 1.25 << 3.75;
141 C << 1.5 << 7.5 << 4.25 << 0.0 << 7.25;
143 R << 2.5 << 3.25 << 5.5 << 7 << 11.25 << 13.5 << 0.0 << 1.5 << 3.5;
146 DCR( D.
nric(), C.
nric(), 5, R.nric(), 9, M.nric() );
151 A.
Row(1) << 2 << 7 << 3 << 6;
152 A.
Row(2) << 6 << 2 << 5 << 9;
153 A.
Row(3) << 1 << 0 << 1 << 6;
154 B.
Row(1) << 2 << 8 << 4 << 5 << 3;
155 B.
Row(2) << 1 << 7 << 5 << 3 << 9;
156 B.
Row(3) << 7 << 8 << 2 << 1 << 6;
157 B.
Row(4) << 5 << 2 << 9 << 0 << 9;
161 for (
int i = 1; i <= 3; ++i)
for (
int j = 1; j <= 5; ++j)
163 X.
nric()[i][j] = 0.0;
164 for (
int k = 1; k <= 4; ++k)
175 C << 3 << 7 << 5 << 1 << 4 << 2 << 3 << 9 << 1 << 3;
177 R << 2 << 3 << 5 << 7 << 11 << 13 << -3 << -4 << 2 << 4;
184 UT << 3 << 5 << 2 << 1 << 7
194 << 0 << 2 << 1 << 9 << 2;
200 LT1.
Row(2) << 2 << 3;
201 LT1.
Row(3) << 1 << 0 << 7;
202 LT1.
Row(4) << 9 << 8 << 1 << 2;
203 LT1.
Row(5) << 0 << 2 << 1 << 9 << 2;
209 M = LTX * 2 - LT;
Print(M);
213 M = LTX * 2 - LT;
Print(M);
215 M = UTX * 2 - UT;
Print(M);
217 M = UTX * 2 - UT;
Print(M);
225 BM1.
Row(1) << 3 << 8 << 4 << 1;
226 BM1.
Row(2) << 5 << 1 << 9 << 7 << 2;
227 BM1.
Row(3) << 1 << 0 << 6 << 3 << 1 << 3;
228 BM1.
Row(4) << 4 << 2 << 5 << 2 << 4;
229 BM1.
Row(5) << 3 << 3 << 9 << 1;
230 BM1.
Row(6) << 4 << 2 << 9;
232 BM2.
Row(1) << 2.5 << 7.5;
233 BM2.
Row(2) << 1.5 << 3.0 << 8.5;
234 BM2.
Row(3) << 6.0 << 6.5 << 7.0;
235 BM2.
Row(4) << 2.5 << 2.0 << 8.0;
236 BM2.
Row(5) << 0.5 << 4.5 << 3.5;
237 BM2.
Row(6) << 9.5 << 7.5;
238 Matrix RM1 = BM1, RM2 = BM2;
240 GenericMatrix GRM1 = RM1, GBM1 = BM1, GRM2 = RM2, GBM2 = BM2;
242 GRM1 |= Z; GBM1 |= Z; GRM2 &= Z.
t(); GBM2 &= Z.
t();
243 X = GRM1 - BM1;
Print(X); X = GBM1 - BM1;
Print(X);
244 X = GRM2 - BM2;
Print(X); X = GBM2 - BM2;
Print(X);
246 GRM1 = RM1; GBM1 = BM1; GRM2 = RM2; GBM2 = BM2;
247 GRM1 *= GRM2; GBM1 *= GBM2;
248 X = GRM1 - BM1 * BM2;
Print(X);
249 X = RM1 * RM2 - GBM1;
Print(X);
251 GRM1 = RM1; GBM1 = BM1; GRM2 = RM2; GBM2 = BM2;
252 GRM1 *= GBM2; GBM1 *= GRM2;
253 X = GRM1 - BM1 * BM2;
Print(X);
254 X = RM1 * RM2 - GBM1;
Print(X);
257 GRM1 = RM1; X -= GRM1.
t();
Print(X); X = BM1X - BM1.
t();
Print(X);
261 GBM1 = BM1; GBM1 *= 4; GRM1 = RM1; GRM1 *= 4;
265 BX = LES1.
i() * GBM1; BX -= BM1 * 2; X = BX;
Print(X);
267 BX = LES2.
i() * GBM1; BX -= BM1 * 2; X = BX;
Print(X);
268 BX = D.
i() * GBM1; BX -= BM1 * 2; X = BX;
Print(X);
269 BX = IM.
i() * GBM1; BX -= BM1 * 2; X = BX;
Print(X);
270 BX = IM.
i(); BX *= GBM1; BX -= BM1 * 2; X = BX;
Print(X);
275 X = 2 * SBM -
SP(RM1, RM1.
t());
Print(X);
278 D << 2.5 << 7.5 << 2 << 5 << 4.5 << 7.5;
279 BX = D.
i() * BM1; X = BX - D.
i() * RM1;
281 BX = D.
i(); BX *= BM1; X = BX - D.
i() * RM1;
283 SBM <<
SP(BM1, BM1.t());
284 BX = D.
i() * SBM; X = BX - D.
i() *
SP(RM1, RM1.
t());
289 if (BX.BandWidth() != BM1.BandWidth()) X = 5;
Real Sum(const BaseMatrix &B)
static void DCR(Real d[], Real c[], int m, Real r[], int n, Real **dcr)
SPMatrix SP(const BaseMatrix &, const BaseMatrix &)
void swap(Matrix &A, Matrix &B)
Real DotProduct(const Matrix &A, const Matrix &B)
void Clean(Matrix &A, Real c)
TransposedMatrix t() const
void SVD(const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
The usual rectangular matrix.
void SortDescending(GeneralMatrix &gm)
Rectangular matrix for use with Numerical Recipes in C.
MatedMatrix AsMatrix(int m, int n) const
void Transposer(const GenericMatrix &GM1, GenericMatrix &GM2)
GetSubMatrix Row(int f) const
void Print(const Matrix &X)
The classes for matrices that can contain data are derived from this.
ReturnMatrix TestReturn(const GeneralMatrix &gm)
A matrix which can be of any GeneralMatrix type.