Skip to content

Commit fb37ba4

Browse files
author
--global
committed
Update and extend the documentation of expm, logm and sqrtm
1 parent e66175b commit fb37ba4

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

base/docs/helpdb.jl

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7006,7 +7006,19 @@ doc"""
70067006
::
70077007
logm(A)
70087008
7009-
Compute the matrix logarithm of ``A``.
7009+
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 nonprincipal matrix function is returned.
7010+
7011+
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.
7012+
7013+
.. [AH12] Awad H. Al-Mohy and Nicholas J. Higham, "Improved inverse scaling
7014+
and squaring algorithms for the matrix logarithm", SIAM Journal on
7015+
Scientific Computing, 34(4), 2012, C153-C169.
7016+
`doi:/10.1137/110852553 <http://dx.doi.org/10.1137/110852553>`
7017+
.. [AHR13] Awad H. Al-Mohy, Nicholas J. Higham and Samuel D. Relton,
7018+
"Computing the Fréchet derivative of the matrix logarithm and estimating
7019+
the condition number", SIAM Journal on Scientific Computing, 35(4), 2013,
7020+
C394-C410.
7021+
`doi:/10.1137/120885991 <http://dx.doi.org/10.1137/120885991>`
70107022
```
70117023
"""
70127024
logm
@@ -10713,9 +10725,13 @@ doc"""
1071310725
::
1071410726
sqrtm(A)
1071510727
10716-
Compute the matrix square root of ``A``. If ``B = sqrtm(A)``, then ``B*B == A`` within roundoff error.
10728+
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.
1071710729
10718-
``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.
10730+
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.
10731+
10732+
.. [BH83] Åke Björck and Sven Hammarling, "A Schur method for the square root
10733+
of a matrix", Linear Algebra and its Applications, 52-53, 1983, 127-140.
10734+
`doi:/10.1016/0024-3795(83)80010-X <http://dx.doi.org/10.1016/0024-3795(83)80010-X>`
1071910735
```
1072010736
"""
1072110737
sqrtm
@@ -10750,7 +10766,17 @@ doc"""
1075010766
::
1075110767
expm(A)
1075210768
10753-
Compute the matrix exponential of ``A``.
10769+
Compute the matrix exponential of ``A``, defined by
10770+
10771+
.. math::
10772+
e^A = \sum_{n=0}^{\inf} \dfrac{A^n}{n!}.
10773+
10774+
For symmetric or Hermitian ``A``, an eigendecomposition (:func:`eigfact`) is used, otherwise the scaling and squaring algorithm (see [H05]_) is chosen.
10775+
10776+
.. [H05] Nicholas J. Higham, "The squaring and scaling method for the matrix
10777+
exponential revisited", SIAM Journal on Matrix Analysis and Applications,
10778+
26(4), 2005, 1179-1193.
10779+
`doi:/10.1137/090768539 <http://dx.doi.org/10.1137/090768539>`
1075410780
```
1075510781
"""
1075610782
expm

base/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export
6666
eigvals!,
6767
eigvecs,
6868
expm,
69-
sqrtm,
7069
eye,
7170
factorize,
7271
givens,
@@ -106,6 +105,7 @@ export
106105
schur,
107106
schurfact!,
108107
schurfact,
108+
sqrtm,
109109
svd,
110110
svdfact!,
111111
svdfact,

base/linalg/dense.jl

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

310310
if isreal(A) && ~np_real_eigs

test/linalg/dense.jl

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

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

358358
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)