Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

# logm

Matrix logarithm

## Syntax

``L = logm(A)``
``[L,exitflag] = logm(A)``

## Description

````L = logm(A)` is the principal matrix logarithm of `A`, the inverse of `expm(A)`. The output, `L`, is the unique logarithm for which every eigenvalue has imaginary part lying strictly between –π and π. If `A` is singular or has any eigenvalues on the negative real axis, then the principal logarithm is undefined. In this case, `logm` computes a nonprincipal logarithm and returns a warning message.```

example

````[L,exitflag] = logm(A)` returns a scalar `exitflag` that describes the exit condition of `logm`:If `exitflag = 0`, the algorithm was successfully completed.If `exitflag = 1`, too many matrix square roots had to be computed. However, the computed value of `L` might still be accurate.```

## Examples

collapse all

Calculate the matrix exponential of a matrix, `A`.

```A = [1 1 0; 0 0 2; 0 0 -1]; Y = expm(A)```
```Y = 3×3 2.7183 1.7183 1.0862 0 1.0000 1.2642 0 0 0.3679 ```

Calculate the matrix logarithm of `Y` to reproduce the original matrix, `A`.

`P = logm(Y)`
```P = 3×3 1.0000 1.0000 0.0000 0 0 2.0000 0 0 -1.0000 ```

`log(A)` involves taking the logarithm of zero, so it produces inferior results.

`Q = log(A)`
```Q = 3×3 complex 0.0000 + 0.0000i 0.0000 + 0.0000i -Inf + 0.0000i -Inf + 0.0000i -Inf + 0.0000i 0.6931 + 0.0000i -Inf + 0.0000i -Inf + 0.0000i 0.0000 + 3.1416i ```

## Input Arguments

collapse all

Input matrix, specified as a square matrix.

Data Types: `single` | `double`
Complex Number Support: Yes

## Tips

• If `A` is real symmetric or complex Hermitian, then so is `logm(A)`.

• Some matrices, like `A = [0 1; 0 0]`, do not have any logarithms, real or complex, so `logm` cannot be expected to produce one.

## Algorithms

The algorithm `logm` uses is described in [1] and [2].

## References

[1] Al-Mohy, A. H. and Nicholas J. Higham, “Improved inverse scaling and squaring algorithms for the matrix logarithm,” SIAM J. Sci. Comput., 34(4), pp. C153–C169, 2012

[2] Al-Mohy, A. H., Higham, Nicholas J. and Samuel D. Relton, “Computing the Frechet derivative of the matrix logarithm and estimating the condition number,” SIAM J. Sci. Comput.,, 35(4), pp. C394–C410, 2013