diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-06-07 14:44:43 +0100 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-06-07 14:44:43 +0100 |
commit | 8c8ab9ae103930e21da76ed6dcbaa585e8af7ff4 (patch) | |
tree | 3bef2b3707b0e0efa6135e791fa7e060cc83debf /unsupported/test | |
parent | a6d42e28fe445dca105552e8f2a54254102f4c4a (diff) |
Implement matrix logarithm + test + docs.
Currently, test matrix_function_1 fails due to bug #288.
Diffstat (limited to 'unsupported/test')
-rw-r--r-- | unsupported/test/matrix_function.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/unsupported/test/matrix_function.cpp b/unsupported/test/matrix_function.cpp index 04167abfb..c2ca5d5f1 100644 --- a/unsupported/test/matrix_function.cpp +++ b/unsupported/test/matrix_function.cpp @@ -121,6 +121,26 @@ void testMatrixExponential(const MatrixType& A) } template<typename MatrixType> +void testMatrixLogarithm(const MatrixType& A) +{ + typedef typename internal::traits<MatrixType>::Scalar Scalar; + typedef typename NumTraits<Scalar>::Real RealScalar; + typedef std::complex<RealScalar> ComplexScalar; + + MatrixType scaledA; + RealScalar maxImagPartOfSpectrum = A.eigenvalues().imag().cwiseAbs().maxCoeff(); + if (maxImagPartOfSpectrum >= 0.9 * M_PI) + scaledA = A * 0.9 * M_PI / maxImagPartOfSpectrum; + else + scaledA = A; + + // identity X.exp().log() = X only holds if Im(lambda) < pi for all eigenvalues of X + MatrixType expA = scaledA.exp(); + MatrixType logExpA = expA.log(); + VERIFY_IS_APPROX(logExpA, scaledA); +} + +template<typename MatrixType> void testHyperbolicFunctions(const MatrixType& A) { // Need to use absolute error because of possible cancellation when @@ -157,6 +177,7 @@ template<typename MatrixType> void testMatrix(const MatrixType& A) { testMatrixExponential(A); + testMatrixLogarithm(A); testHyperbolicFunctions(A); testGonioFunctions(A); } |