61 cout <<
"\n LU decomposition test \n";
62 cout <<
"initial matrix: \n";
64 cout <<
" " << a(0, 0) << endl;
72 cout <<
"\n after decomposition: ";
73 cout << b(0, 0) << endl;
92 cout << indx[0] <<
" " << c[0] << endl;
97 cout <<
"\n solution vector x: ";
135 cout <<
"\n LU decomposition test \n";
136 cout <<
"initial matrix: \n";
137 for (
Index i = 0; i < 4; i++) {
139 for (
Index j = 0; j < 4; j++) cout <<
" " << a(i, j);
149 cout <<
"\n after decomposition";
150 for (
Index i = 0; i < 4; i++) {
152 for (
Index j = 0; j < 4; j++) cout <<
" " << b(i, j);
161 for (
Index i = 0; i < 4; i++) l(i, i) = 1.0;
166 cout <<
"\n Matrix L";
167 for (
Index i = 0; i < 4; i++) {
169 for (
Index j = 0; j < 4; j++) cout <<
" " << l(i, j);
178 cout <<
"\n Matrix U";
179 for (
Index i = 0; i < 4; i++) {
181 for (
Index j = 0; j < 4; j++) cout <<
" " << u(i, j);
188 cout <<
"\n product L*U";
189 for (
Index i = 0; i < 4; i++) {
191 for (
Index j = 0; j < 4; j++) cout <<
" " << lu(i, j);
209 cout <<
"\n vector indx";
210 for (
Index i = 0; i < 4; i++) {
212 cout << indx[i] <<
" " << c[i];
219 cout <<
"\n solution vector x" << endl;
220 for (
Index i = 0; i < 4; i++) {
226 cout <<
"\n test solution LU*x";
229 for (
Index i = 0; i < 4; i++) {
261 srand((
unsigned int)
time(0));
263 cout << endl << endl <<
"Testing linear system solution: n = " << dim;
264 cout <<
", ntests = " << ntests << endl;
265 cout << endl << setw(10) <<
"Test no." << setw(20) <<
"lubacksub(...)";
266 cout << setw(20) <<
"solve(...)" << endl << endl;
268 for (
Index i = 0; i < ntests; i++) {
282 cout << setw(10) << i << setw(20) << err;
289 cout << setw(20) << err << endl;
293 cout <<
"A:" << endl << A << endl << endl;
294 cout <<
"x0:" << endl <<
x0 << endl << endl;
295 cout <<
"x:" << endl <<
x << endl << endl;
296 cout <<
"Permutation Vector:" << endl << indx << endl;
327 srand((
unsigned int)
time(0));
329 cout << endl << endl <<
"Testing matrix inversion: n = " << dim;
330 cout <<
", ntests = " << ntests << endl << endl;
331 cout << setw(10) <<
"Test no." << setw(20) <<
"Max. rel. error" << endl
334 for (
Index i = 0; i < ntests; i++) {
344 cout << setw(10) << i << setw(20) << err << endl;
348 cout <<
"A:" << endl << A << endl << endl;
349 cout <<
"Ainv:" << endl << Ainv << endl << endl;
350 cout <<
"A*Ainv:" << endl << I << endl << endl;
385 cout <<
"\n Exponential of Matrix K";
386 for (
Index i = 0; i < 4; i++) {
388 for (
Index j = 0; j < 4; j++) cout <<
" " << F(i, j);
408 cout <<
"\n Exponential of Matrix A:\n";
436 cout <<
"\n Exponential of Matrix A";
437 for (
Index i = 0; i < 3; i++) {
439 for (
Index j = 0; j < 3; j++) cout <<
" " << F(i, j);
445 Matrix A(dim, dim), F1(dim, dim), F2(dim, dim), tmp1(dim, dim),
446 tmp2(dim, dim), P(dim, dim);
449 const Matrix ZEROES(dim, dim, 0);
452 srand((
unsigned int)
time(0));
454 cout << endl << endl <<
"Testing diagonalize: n = " << dim;
455 cout <<
", ntests = " << ntests << endl;
456 cout << setw(10) <<
"Test no." << setw(25) <<
"Max. rel. expm error";
457 cout << setw(25) <<
"Max. abs. P^-1*A*P-W" << endl << endl;
459 for (
Index i = 0; i < ntests; i++) {
467 Numeric err1 = 0.0, err2 = 0.0;
479 for (
Index j = 0; j < dim; j++) {
485 cout << setw(10) << i << setw(25) << err1 << setw(25) << err2 << endl;
490 ComplexMatrix A(dim, dim), tmp1(dim, dim), tmp2(dim, dim), P(dim, dim);
496 srand((
unsigned int)
time(0));
498 cout << endl << endl <<
"Testing diagonalize: n = " << dim;
499 cout <<
", ntests = " << ntests << endl;
500 cout << setw(10) <<
"Test no.";
501 cout << setw(25) <<
"Max. abs. P^-1*A*P-W" << endl << endl;
503 for (
Index i = 0; i < ntests; i++) {
518 for (
Index j = 0; j < dim; j++) {
524 cout << setw(10) << i << setw(25) << err << endl;
529 for (
Index i = 0; i < nruns; i++) {
531 c = ((
Numeric)rand() / RAND_MAX), d = ((
Numeric)rand() / RAND_MAX),
532 u = ((
Numeric)rand() / RAND_MAX), v = ((
Numeric)rand() / RAND_MAX),
535 Matrix A(4, 4),
F0(4, 4), F1(4, 4), F2(4, 4);
537 A(0, 0) = A(1, 1) = A(2, 2) = A(3, 3) = a;
538 A(0, 1) = A(1, 0) = b;
539 A(0, 2) = A(2, 0) = c;
540 A(0, 3) = A(3, 0) = d;
550 Tensor3 dF1(ndiffs, 4, 4), dF2(ndiffs, 4, 4), dF3(ndiffs, 4, 4),
551 dF4(ndiffs, 4, 4), dA1(ndiffs, 4, 4), dA2(ndiffs, 4, 4);
554 db1 = ((
Numeric)rand() / RAND_MAX),
555 dc1 = ((
Numeric)rand() / RAND_MAX),
556 dd1 = ((
Numeric)rand() / RAND_MAX),
557 du1 = ((
Numeric)rand() / RAND_MAX),
558 dv1 = ((
Numeric)rand() / RAND_MAX),
559 dw1 = ((
Numeric)rand() / RAND_MAX);
562 db2 = ((
Numeric)rand() / RAND_MAX),
563 dc2 = ((
Numeric)rand() / RAND_MAX),
564 dd2 = ((
Numeric)rand() / RAND_MAX),
565 du2 = ((
Numeric)rand() / RAND_MAX),
566 dv2 = ((
Numeric)rand() / RAND_MAX),
567 dw2 = ((
Numeric)rand() / RAND_MAX);
574 dA1(
joker, 1, 2) = du1;
575 dA1(
joker, 2, 1) = -du1;
576 dA1(
joker, 1, 3) = dv1;
577 dA1(
joker, 3, 1) = -dv1;
578 dA1(
joker, 2, 3) = dw1;
579 dA1(
joker, 3, 2) = -dw1;
588 dA2(
joker, 1, 2) = du2;
589 dA2(
joker, 2, 1) = -du2;
590 dA2(
joker, 1, 3) = dv2;
591 dA2(
joker, 3, 1) = -dv2;
592 dA2(
joker, 2, 3) = dw2;
593 dA2(
joker, 3, 2) = -dw2;
600 F1, dF1, dF2, A, dA1, dA2);
602 F2, dF3, dF4, A, dA1, dA2);