19 using namespace NEWMAT;
36 Tracer et(
"Fourteenth test of Matrix package");
43 Real a[] = { 22, 10, 2, 3, 7,
51 int ai[] = { 22, 10, 2, 3, 7,
62 AI << ai; AI -= A;
Print(AI);
63 int b[] = { 13, -1,-11,
70 AI.
Rows(1,2) = 23; AI.
Rows(7,8) = 23;
82 SVD(A, D1, W, W,
true,
false); D1 -= D; W -= U;
85 SVD(A, D1, WX, W,
false,
true); D1 -= D; W -= V;
92 D(1) -= sqrt(1248.0); D(2) -= 20; D(3) -= sqrt(384.0);
96 V = S1 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
97 D = D.
Reverse(); D(1)-=1248; D(2)-=400; D(3)-=384;
101 D = D.
Reverse(); D(1)-=1248; D(2)-=400; D(3)-=384;
106 D = D.
Reverse(); D(1)-=1248; D(2)-=400; D(3)-=384;
110 V = S2 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
111 D = D.
Reverse(); D(1)-=1248; D(2)-=400; D(3)-=384;
115 V = S1 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
116 D(5)-=1248; D(4)-=400; D(3)-=384;
120 V = S2 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
121 D(8)-=1248; D(7)-=400; D(6)-=384;
125 D(5)-=1248; D(4)-=400; D(3)-=384;
130 D(8)-=1248; D(7)-=400; D(6)-=384;
139 for (i=1; i<=20; i++)
for (j=1; j<=21; j++)
140 {
if (i>j) A(i,j) = 0;
else if (i==j) A(i,j) = 21-i;
else A(i,j) = -1; }
151 for (i=1; i<=20; i++) D(i) -= sqrt((22.0-i)*(21.0-i));
154 V = S1 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
156 for (i=1; i<=20; i++) D(i) -= (22-i)*(21-i);
159 V = S2 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
161 for (i=1; i<=20; i++) D(i) -= (22-i)*(21-i);
165 V = S1 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
166 for (i=1; i<=20; i++) D(i) -= (i+1)*i;
169 V = S2 - V * D * V.
t();
Clean(V,0.000000001);
Print(V);
170 for (i=2; i<=21; i++) D(i) -= (i-1)*i;
174 for (i=1; i<=20; i++) D(i) -= (i+1)*i;
177 for (i=2; i<=21; i++) D(i) -= (i-1)*i;
185 for (i=1; i<=30; i++)
for (j=1; j<=30; j++)
186 {
if (i>j) A(i,j) = 0;
else if (i==j) A(i,j) = 1;
else A(i,j) = -1; }
198 Test(1) = d1 - 1; Test(2) = d2 - 1; Test(3) = d3 - 1;
202 A << a << b << a << b;
205 SU = U.
t() * U - I;
Clean(SU,0.000000001);
Print(SU);
206 SV = V.
t() * V - I;
Clean(SV,0.000000001);
Print(SV);
207 B = U * D * V.
t() - A;
Clean(B,0.000000001);
Print(B);
210 Clean(D,0.000000001);
212 A << a << a << b << b;
214 SU = U.
t() * U - I;
Clean(SU,0.000000001);
Print(SU);
215 SV = V.
t() * V - I;
Clean(SV,0.000000001);
Print(SV);
216 B = U * D * V.
t() - A;
Clean(B,0.000000001);
Print(B);
219 Clean(D,0.000000001);
236 A(a+0,a+2) = 1; A(a+0,a+18) = -1;
237 A(a+1,a+9) = 1; A(a+1,a+12) = -1;
238 A(a+2,a+11) = 1; A(a+2,a+12) = -1;
239 A(a+3,a+10) = 1; A(a+3,a+19) = -1;
240 A(a+4,a+16) = 1; A(a+4,a+19) = -1;
241 A(a+5,a+17) = 1; A(a+5,a+18) = -1;
242 A(a+6,a+10) = 1; A(a+6,a+4) = -1;
243 A(a+7,a+3) = 1; A(a+7,a+2) = -1;
244 A(a+8,a+14) = 1; A(a+8,a+15) = -1;
245 A(a+9,a+13) = 1; A(a+9,a+16) = -1;
246 A(a+10,a+8) = 1; A(a+10,a+9) = -1;
247 A(a+11,a+1) = 1; A(a+11,a+15) = -1;
248 A(a+12,a+16) = 1; A(a+12,a+4) = -1;
249 A(a+13,a+6) = 1; A(a+13,a+9) = -1;
250 A(a+14,a+5) = 1; A(a+14,a+4) = -1;
251 A(a+15,a+0) = 1; A(a+15,a+1) = -1;
252 A(a+16,a+14) = 1; A(a+16,a+0) = -1;
253 A(a+17,a+7) = 1; A(a+17,a+6) = -1;
254 A(a+18,a+13) = 1; A(a+18,a+5) = -1;
255 A(a+19,a+7) = 1; A(a+19,a+8) = -1;
256 A(a+20,a+17) = 1; A(a+20,a+3) = -1;
257 A(a+21,a+6) = 1; A(a+21,a+11) = -1;
272 tmp = U * S * V.
t() - A ;
281 A.
Row(1) << 1.00 << 0.07 << 0.05 << 0.00 << 0.06
282 << 0.09 << 0.03 << 0.02 << 0.02 << -0.03;
283 A.
Row(2) << 0.07 << 1.00 << 0.05 << 0.05 << -0.03
284 << 0.07 << 0.00 << 0.07 << 0.00 << 0.02;
285 A.
Row(3) << 0.05 << 0.05 << 1.00 << 0.05 << 0.02
286 << 0.01 << -0.05 << 0.04 << 0.05 << -0.03;
287 A.
Row(4) << 0.00 << 0.05 << 0.05 << 1.00 << -0.05
288 << 0.04 << 0.01 << 0.02 << -0.05 << 0.00;
289 A.
Row(5) << 0.06 << -0.03 << 0.02 << -0.05 << 1.00
290 << -0.03 << 0.02 << -0.02 << 0.04 << 0.00;
291 A.
Row(6) << 0.09 << 0.07 << 0.01 << 0.04 << -0.03
292 << 1.00 << -0.06 << 0.08 << -0.02 << -0.10;
293 A.
Row(7) << 0.03 << 0.00 << -0.05 << 0.01 << 0.02
294 << -0.06 << 1.00 << 0.09 << 0.12 << -0.03;
295 A.
Row(8) << 0.02 << 0.07 << 0.04 << 0.02 << -0.02
296 << 0.08 << 0.09 << 1.00 << 0.00 << -0.02;
297 A.
Row(9) << 0.02 << 0.00 << 0.05 << -0.05 << 0.04
298 << -0.02 << 0.12 << 0.00 << 1.00 << 0.02;
299 A.
Row(10) << -0.03 << 0.02 << -0.03 << 0.00 << 0.00
300 << -0.10 << -0.03 << -0.02 << 0.02 << 1.00;
331 B.
Row(2) << 0.07 << 1.00;
332 B.
Row(3) << 0.05 << 0.05 << 1.00;
333 B.
Row(4) << 0.00 << 0.05 << 0.05 << 1.00;
334 B.
Row(5) << 0.06 << -0.03 << 0.02 << -0.05 << 1.00;
335 B.
Row(6) << 0.09 << 0.07 << 0.01 << 0.04 << -0.03
337 B.
Row(7) << 0.03 << 0.00 << -0.05 << 0.01 << 0.02
339 B.
Row(8) << 0.02 << 0.07 << 0.04 << 0.02 << -0.02
340 << 0.08 << 0.09 << 1.00;
341 B.
Row(9) << 0.02 << 0.00 << 0.05 << -0.05 << 0.04
342 << -0.02 << 0.12 << 0.00 << 1.00;
343 B.
Row(10) << -0.03 << 0.02 << -0.03 << 0.00 << 0.00
344 << -0.10 << -0.03 << -0.02 << 0.02 << 1.00;
355 A.
Row(1) << 1.13324e+012 << 3.68788e+011 << 3.35163e+009
356 << 3.50193e+011 << 1.25335e+011 << 1.02212e+009
357 << 3.16602e+009 << 1.02418e+009 << 9.42959e+006;
358 A.
Row(2) << 3.68788e+011 << 1.67128e+011 << 1.27449e+009
359 << 1.25335e+011 << 6.05413e+010 << 4.34573e+008
360 << 1.02418e+009 << 4.69192e+008 << 3.61098e+006;
361 A.
Row(3) << 3.35163e+009 << 1.27449e+009 << 1.25571e+007
362 << 1.02212e+009 << 4.34573e+008 << 3.69769e+006
363 << 9.42959e+006 << 3.61098e+006 << 3.59450e+004;
364 A.
Row(4) << 3.50193e+011 << 1.25335e+011 << 1.02212e+009
365 << 1.43514e+011 << 5.42310e+010 << 4.15822e+008
366 << 1.23068e+009 << 4.31545e+008 << 3.58714e+006;
367 A.
Row(5) << 1.25335e+011 << 6.05413e+010 << 4.34573e+008
368 << 5.42310e+010 << 2.76601e+010 << 1.89102e+008
369 << 4.31545e+008 << 2.09778e+008 << 1.51083e+006;
370 A.
Row(6) << 1.02212e+009 << 4.34573e+008 << 3.69769e+006
371 << 4.15822e+008 << 1.89102e+008 << 1.47143e+006
372 << 3.58714e+006 << 1.51083e+006 << 1.30165e+004;
373 A.
Row(7) << 3.16602e+009 << 1.02418e+009 << 9.42959e+006
374 << 1.23068e+009 << 4.31545e+008 << 3.58714e+006
375 << 1.12335e+007 << 3.54778e+006 << 3.34311e+004;
376 A.
Row(8) << 1.02418e+009 << 4.69192e+008 << 3.61098e+006
377 << 4.31545e+008 << 2.09778e+008 << 1.51083e+006
378 << 3.54778e+006 << 1.62552e+006 << 1.25885e+004;
379 A.
Row(9) << 9.42959e+006 << 3.61098e+006 << 3.59450e+004
380 << 3.58714e+006 << 1.51083e+006 << 1.30165e+004
381 << 3.34311e+004 << 1.25885e+004 << 1.28000e+002;
413 A.
Row(1)<<-0.4343<<-0.0445<<-0.4582<<-0.1612<<-0.3191<<-0.6784<<0.1068<<0;
414 A.
Row(2)<<0.5791<<0.5517<<0.2575<<-0.1055<<-0.0437<<-0.5282<<0.0442<<0;
415 A.
Row(3)<<0.5709<<-0.5179<<-0.3275<<0.2598<<-0.196<<-0.1451<<-0.4143<<0;
416 A.
Row(4)<<0.2785<<-0.5258<<0.1251<<-0.4382<<0.0514<<-0.0446<<0.6586<<0;
417 A.
Row(5)<<0.2654<<0.3736<<-0.7436<<-0.0122<<0.0376<<0.3465<<0.3397<<0;
418 A.
Row(6)<<0.0173<<-0.0056<<-0.1903<<-0.7027<<0.4863<<-0.0199<<-0.4825<<0;
419 A.
Row(7)<<0.0434<<0.0966<<0.1083<<-0.4576<<-0.7857<<0.3425<<-0.1818<<0;
420 A.
Row(8)<<0.0<<0.0<<0.0<<0.0<<0.0<<0.0<<0.0<<-1.0;
425 U *= U.
t(); U -= I;
Clean(U,0.000000001);
Print(U);
426 V *= V.
t(); V -= I;
Clean(V,0.000000001);
Print(V);
436 for (i = 1; i <= 15; ++i)
for (j = 1; j <= 10; ++j)
437 A(i, j) = i + j / 1000.0;
439 D << 0.2 << 0.5 << 0.1 << 0.7 << 0.8 << 0.3 << 0.4 << 0.7 << 0.9 << 0.6;
445 X = Prod - U * D1 * V.
t();
Clean(X,0.000000001);
Print(X);
446 U = A; V = 10 - 2 * A;
449 X = Prod - U * D1 * V.
t();
Clean(X,0.000000001);
Print(X);
452 U = A; V = 10 - 2 * A;
453 D1 = D;
SortSV(D1, U, V,
true); X = D1 - D2;
Print(X);
454 X = Prod - U * D1 * V.
t();
Clean(X,0.000000001);
Print(X);
455 U = A; V = 10 - 2 * A;
456 D1 = D;
SortSV(D1, U,
true); X = D1 - D2;
Print(X);
457 D1 = D;
SortSV(D1, V,
true); X = D1 - D2;
Print(X);
458 X = Prod - U * D1 * V.
t();
Clean(X,0.000000001);
Print(X);
470 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
471 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
472 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
473 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
474 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
475 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
476 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
477 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
478 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
479 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
484 A -= U * Sigma * V.
t();
LogAndSign LogDeterminant() const
void Jacobi(const SymmetricMatrix &X, DiagonalMatrix &D, SymmetricMatrix &A, Matrix &V, bool eivec)
virtual void ReSize(int m, int n)
void EigenValues(const SymmetricMatrix &A, DiagonalMatrix &D)
void SortAscending(GeneralMatrix &gm)
ReversedMatrix Reverse() const
void CheckIsSorted(const DiagonalMatrix &D, bool ascending=false)
void Clean(Matrix &A, Real c)
GetSubMatrix Column(int f) const
TransposedMatrix t() const
Real MaximumAbsoluteValue(const BaseMatrix &B)
void SVD(const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
The usual rectangular matrix.
void SortDescending(GeneralMatrix &gm)
FloatVector FloatVector * a
GetSubMatrix Row(int f) const
GetSubMatrix SubMatrix(int fr, int lr, int fc, int lc) const
void Print(const Matrix &X)
void SortSV(DiagonalMatrix &D, Matrix &U, bool ascending=false)
GetSubMatrix Rows(int f, int l) const