mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Implement matrix logarithm + test + docs.
Currently, test matrix_function_1 fails due to bug #288.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user