Implement matrix logarithm + test + docs.

Currently, test matrix_function_1 fails due to bug #288.
This commit is contained in:
Jitse Niesen
2011-06-07 14:44:43 +01:00
parent a6d42e28fe
commit 8c8ab9ae10
6 changed files with 434 additions and 0 deletions

View File

@@ -120,6 +120,26 @@ void testMatrixExponential(const MatrixType& A)
VERIFY_IS_APPROX(A.exp(), A.matrixFunction(StdStemFunctions<ComplexScalar>::exp));
}
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)
{
@@ -157,6 +177,7 @@ template<typename MatrixType>
void testMatrix(const MatrixType& A)
{
testMatrixExponential(A);
testMatrixLogarithm(A);
testHyperbolicFunctions(A);
testGonioFunctions(A);
}