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";
139 for (
Index j = 0; j < 4; j++) cout <<
" " << a(
i, j);
149 cout <<
"\n after decomposition";
152 for (
Index j = 0; j < 4; j++) cout <<
" " << b(
i, j);
166 cout <<
"\n Matrix L";
169 for (
Index j = 0; j < 4; j++) cout <<
" " << l(
i, j);
178 cout <<
"\n Matrix U";
181 for (
Index j = 0; j < 4; j++) cout <<
" " << u(
i, j);
188 cout <<
"\n product L*U";
191 for (
Index j = 0; j < 4; j++) cout <<
" " << lu(
i, j);
209 cout <<
"\n vector indx";
212 cout << indx[
i] <<
" " << c[
i];
219 cout <<
"\n solution vector x" << endl;
226 cout <<
"\n test solution LU*x";
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";
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";
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;
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);
INDEX Index
The type to use for all integer numbers and indices.
Utility functions for testing.
void matrix_exp2(MatrixView F, ConstMatrixView A)
void test_complex_diagonalize(Index ntests, Index dim)
void matrix_exp(MatrixView F, ConstMatrixView A, const Index &q)
General exponential of a Matrix.
void lubacksub(VectorView x, ConstMatrixView LU, ConstVectorView b, const ArrayOfIndex &indx)
LU backsubstitution.
void special_matrix_exp_and_dmatrix_exp_dx_for_rt(MatrixView F, Tensor3View dF_upp, Tensor3View dF_low, ConstMatrixView A, ConstTensor3View dA_upp, ConstTensor3View dA_low, const Index &q)
Special exponential of a Matrix with their derivatives.
Linear algebra functions.
cmplx FADDEEVA() w(cmplx z, double relerr)
void test_lusolve4D(void)
void random_fill_vector(VectorView v, Numeric range, bool positive)
Fill vector with random values.
This file contains the definition of Array.
void random_fill_matrix_symmetric(MatrixView A, Numeric range, bool positive)
Generate random, symmetric matrix.
void test_matrix_exp1D(void)
Test for the matrix exponential function (3D matrix)
void test_inv(Index ntests, Index dim, bool verbose=false)
Test matrix inversion.
void test_matrix_exp3D(void)
Test for the matrix exponential function (3D matrix)
void test_real_diagonalize(Index ntests, Index dim)
NUMERIC Numeric
The type to use for all floating point numbers.
void test_matrix_exp4D(void)
Test for the matrix exponential function (4D matrix)
void cayley_hamilton_fitted_method_4x4_propmat_to_transmat__explicit(MatrixView F, ConstMatrixView A)
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
void diagonalize(MatrixView P, VectorView WR, VectorView WI, ConstMatrixView A)
Matrix Diagonalization.
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
void cayley_hamilton_fitted_method_4x4_propmat_to_transmat__eigen(MatrixView F, ConstMatrixView A)
void test_lusolve1D(void)
Numeric get_maximum_error(ConstVectorView v1, ConstVectorView v2, bool relative)
Maximum element-wise error of two vectors.
void test_matrix_exp_propmat(Index nruns, Index ndiffs)
void id_mat(MatrixView I)
Identity Matrix.
void test_solve_linear_system(Index ntests, Index dim, bool verbose)
Test ludcmp and lubacksub by solving a linear system of equations.
ComplexConstMatrixViewMap MapToEigen(const ConstComplexMatrixView &A)
void solve(VectorView w, const CovarianceMatrix &A, ConstVectorView v)
void ludcmp(Matrix &LU, ArrayOfIndex &indx, ConstMatrixView A)
LU decomposition.
void random_fill_matrix_pos_def(MatrixView A, Numeric range, bool positive)
Generate random, positive definite matrix.