Skip to content

Commit 0a894fa

Browse files
committed
Documentation for expm, logm and sqrtm
1 parent d4a5850 commit 0a894fa

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

base/linalg/dense.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function logm(A::StridedMatrix)
308308
end
309309
end
310310
if np_real_eigs
311-
warn("Matrix with nonpositive real eigenvalues, a nonprimary matrix logarithm will be returned.")
311+
warn("Matrix with nonpositive real eigenvalues, a nonprincipal matrix logarithm will be returned.")
312312
end
313313

314314
if isreal(A) && ~np_real_eigs

doc/stdlib/linalg.rst

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,17 +638,45 @@ Linear algebra functions in Julia are largely implemented by calling functions f
638638

639639
.. function:: expm(A)
640640

641-
Compute the matrix exponential of ``A``.
641+
Compute the matrix exponential of ``A``, defined by
642+
643+
.. math::
644+
645+
e^A = \sum_{n=0}^{\inf} \dfrac{A^n}{n!}.
646+
647+
For symmetric or Hermitian ``A``, an eigendecomposition (:func:`eigfact`) is used, otherwise the scaling and squaring algorithm (see [H05]_) is chosen.
648+
649+
.. [H05] Nicholas J. Higham, "The squaring and scaling method for the matrix
650+
exponential revisited", SIAM Journal on Matrix Analysis and Applications,
651+
26(4), 2005, 1179-1193.
652+
`doi:/10.1137/090768539 <http://dx.doi.org/10.1137/090768539>`
642653
643654
.. function:: logm(A)
644655

645-
Compute the matrix logarithm of ``A``.
656+
If ``A`` has no negative real eigenvalue, compute the principal matrix logarithm of ``A``, i.e. the unique matrix :math:`X` such that :math:`e^X = A` and :math:`-\pi < Im(\lambda) < \pi` for all the eigenvalues :math:`\lambda` of :math:`X`. If ``A`` has nonpositive eigenvalues, a warning is printed and whenever possible a nonprimary matrix function is returned.
657+
658+
If `A` is symmetric or Hermitian, its eigendecomposition (:func:`eigfact`) is used, if `A` is triangular an improved version of the inverse scaling and squaring method is employed (see [AH12]_ and [AHR13]_). For general matrices, the complex Schur form (:func:`schur`) is computed and the triangular algorithm is used on the triangular factor.
659+
660+
661+
.. [AH12] Awad H. Al-Mohy and Nicholas J. Higham, "Improved inverse scaling
662+
and squaring algorithms for the matrix logarithm", SIAM Journal on
663+
Scientific Computing, 34(4), 2012, C153-C169.
664+
`doi:/10.1137/110852553 <http://dx.doi.org/10.1137/110852553>`
665+
.. [AHR13] Awad H. Al-Mohy, Nicholas J. Higham and Samuel D. Relton,
666+
"Computing the Fréchet derivative of the matrix logarithm and estimating
667+
the condition number", SIAM Journal on Scientific Computing, 35(4), 2013,
668+
C394-C410.
669+
`doi:/10.1137/120885991 <http://dx.doi.org/10.1137/120885991>`
646670
647671
.. function:: sqrtm(A)
648672

649-
Compute the matrix square root of ``A``. If ``B = sqrtm(A)``, then ``B*B == A`` within roundoff error.
673+
If ``A`` has no negative real eigenvalues, compute the principal matrix square root of ``A``, that is the unique matrix :math:`X` with eigenvalues having positive real part such that :math:`X^2 = A`. Otherwise, a nonprincipal square root is returned.
674+
675+
If `A` is symmetric or Hermitian, its eigendecomposition (:func:`eigfact`) is used to compute the square root. Otherwise, the square root is determined by means of the Björck-Hammarling method, which computes the complex Schur form (:func:`schur`) and then the complex square root of the triangular factor.
650676

651-
``sqrtm`` uses a polyalgorithm, computing the matrix square root using Schur factorizations (:func:`schurfact`) unless it detects the matrix to be Hermitian or real symmetric, in which case it computes the matrix square root from an eigendecomposition (:func:`eigfact`). In the latter situation for positive definite matrices, the matrix square root has ``Real`` elements, otherwise it has ``Complex`` elements.
677+
.. [BH83] Åke Björck and Sven Hammarling, "A Schur method for the square root
678+
of a matrix", Linear Algebra and its Applications, 52-53, 1983, 127-140.
679+
`doi:/10.1016/0024-3795(83)80010-X <http://dx.doi.org/10.1016/0024-3795(83)80010-X>`
652680
653681
.. function:: lyap(A, C)
654682

test/linalg3.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ for elty in (Float64, Complex{Float64})
179179
A5 = convert(Matrix{elty}, [1 1 0 1; 0 1 1 0; 0 0 1 1; 1 0 0 1])
180180
@test_approx_eq expm(logm(A5)) A5
181181
s = readline(rd)
182-
@test contains(s, "WARNING: Matrix with nonpositive real eigenvalues, a nonprimary matrix logarithm will be returned.")
182+
@test contains(s, "WARNING: Matrix with nonpositive real eigenvalues, a nonprincipal matrix logarithm will be returned.")
183183

184184
A6 = convert(Matrix{elty}, [-5 2 0 0 ; 1/2 -7 3 0; 0 1/3 -9 4; 0 0 1/4 -11])
185185
@test_approx_eq expm(logm(A6)) A6
186186
s = readline(rd)
187-
@test contains(s, "WARNING: Matrix with nonpositive real eigenvalues, a nonprimary matrix logarithm will be returned.")
187+
@test contains(s, "WARNING: Matrix with nonpositive real eigenvalues, a nonprincipal matrix logarithm will be returned.")
188188
redirect_stderr(OLD_STDERR)
189189

190190
A7 = convert(Matrix{elty}, [1 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1])

0 commit comments

Comments
 (0)