From f71f878babec8ffb01e563d2e234ecd56f7bc461 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Wed, 12 Aug 2009 15:44:22 +0100 Subject: Add support for matrix exponential of floats and complex numbers. --- unsupported/test/matrixExponential.cpp | 62 +++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'unsupported/test/matrixExponential.cpp') diff --git a/unsupported/test/matrixExponential.cpp b/unsupported/test/matrixExponential.cpp index 0ec4fae90..9a6c335d8 100644 --- a/unsupported/test/matrixExponential.cpp +++ b/unsupported/test/matrixExponential.cpp @@ -34,26 +34,47 @@ double binom(int n, int k) return res; } -void test2dRotation() +template +void test2dRotation(double tol) { - Matrix2d A, B, C; - double angle; + Matrix A, B, C; + T angle; + A << 0, 1, -1, 0; for (int i=0; i<=20; i++) { angle = pow(10, i / 5. - 2); - A << 0, angle, -angle, 0; B << cos(angle), sin(angle), -sin(angle), cos(angle); + ei_matrix_exponential(angle*A, &C); + VERIFY(C.isApprox(B, tol)); + } +} + +template +void test2dHyperbolicRotation(double tol) +{ + Matrix,2,2> A, B, C; + std::complex imagUnit(0,1); + T angle, ch, sh; + + for (int i=0; i<=20; i++) + { + angle = (i-10) / 2.0; + ch = std::cosh(angle); + sh = std::sinh(angle); + A << 0, angle*imagUnit, -angle*imagUnit, 0; + B << ch, sh*imagUnit, -sh*imagUnit, ch; ei_matrix_exponential(A, &C); - VERIFY(C.isApprox(B, 1e-14)); + VERIFY(C.isApprox(B, tol)); } } -void testPascal() +template +void testPascal(double tol) { for (int size=1; size<20; size++) { - MatrixXd A(size,size), B(size,size), C(size,size); + Matrix A(size,size), B(size,size), C(size,size); A.setZero(); for (int i=0; i void randomTest(const MatrixType& m) +template +void randomTest(const MatrixType& m, double tol) { /* this test covers the following files: Inverse.h @@ -80,16 +102,24 @@ template void randomTest(const MatrixType& m) m1 = MatrixType::Random(rows, cols); ei_matrix_exponential(m1, &m2); ei_matrix_exponential(-m1, &m3); - VERIFY(identity.isApprox(m2 * m3, 1e-13)); + VERIFY(identity.isApprox(m2 * m3, tol)); } } void test_matrixExponential() { - CALL_SUBTEST(test2dRotation()); - CALL_SUBTEST(testPascal()); - CALL_SUBTEST(randomTest(Matrix2d())); - CALL_SUBTEST(randomTest(Matrix3d())); - CALL_SUBTEST(randomTest(Matrix4d())); - CALL_SUBTEST(randomTest(MatrixXd(8,8))); + CALL_SUBTEST(test2dRotation(1e-14)); + CALL_SUBTEST(test2dRotation(1e-5)); + CALL_SUBTEST(test2dHyperbolicRotation(1e-14)); + CALL_SUBTEST(test2dHyperbolicRotation(1e-5)); + CALL_SUBTEST(testPascal(1e-5)); + CALL_SUBTEST(testPascal(1e-14)); + CALL_SUBTEST(randomTest(Matrix2d(), 1e-13)); + CALL_SUBTEST(randomTest(Matrix(), 1e-13)); + CALL_SUBTEST(randomTest(Matrix4cd(), 1e-13)); + CALL_SUBTEST(randomTest(MatrixXd(8,8), 1e-13)); + CALL_SUBTEST(randomTest(Matrix2f(), 1e-4)); + CALL_SUBTEST(randomTest(Matrix3cf(), 1e-4)); + CALL_SUBTEST(randomTest(Matrix4f(), 1e-4)); + CALL_SUBTEST(randomTest(MatrixXf(8,8), 1e-4)); } -- cgit v1.2.3