MATLAB Function Reference
logm

Matrix logarithm

Syntax

• ```Y` `=` `logm(X)
[Y,esterr] = logm(X)
```

Description

```Y = logm(X) ``` returns the matrix logarithm: the inverse function of `expm(X)`. Complex results are produced if `X` has negative eigenvalues. A warning message is printed if the computed `expm(Y)` is not close to `X`.

```[Y,esterr] = logm(X) ``` does not print any warning message, but returns an estimate of the relative residual, `norm(expm(Y)-X)/norm(X)`.

Remarks

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

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

Limitations

For most matrices:

• ```logm(expm(X)) = X = expm(logm(X))
```

These identities may fail for some `X`. For example, if the computed eigenvalues of `X` include an exact zero, then `logm(X)` generates infinity. Or, if the elements of `X` are too large, `expm(X)` may overflow.

Examples

Suppose `A` is the 3-by-3 matrix

• ```        1        1        0
0        0        2
0        0       -1
```

and `X` `=` `expm(A)` is

• ```X` `=
`    `2.7183`    `1.7183`    `1.0862
`         `0`    `1.0000`    `1.2642
`         `0`         `0`    `0.3679
```

Then `A = logm(X)` produces the original matrix `A`.

• ```A` `=
`    `1.0000`    `1.0000`    `0.0000
`         `0`         `0`    `2.0000
`         `0`         `0`   `-1.0000
```

But `log(X)` involves taking the logarithm of zero, and so produces

• ```ans =
`    `1.0000`    `0.5413`    `0.0826
`      `-Inf`         `0`    `0.2345
`      `-Inf`      `-Inf`   `-1.0000
```

Algorithm

The matrix functions are evaluated using an algorithm due to Parlett, which is described in [1]. The algorithm uses the Schur factorization of the matrix and may give poor results or break down completely when the matrix has repeated eigenvalues. A warning message is printed when the results may be inaccurate.

`expm`, `funm`, `sqrtm`