MATLAB Function Reference
funm

Evaluate general matrix function

Syntax

• ```F = funm(A,fun)
[F,esterr] = funm(A,fun)
```

Description

```F = funm(A,fun) ``` for a square matrix argument `A`, evaluates the matrix version of the function `fun`. For matrix exponentials, logarithms and square roots, use `expm(A)`, `logm(A)` and `sqrtm(A)` instead.

```[F,esterr] = funm(A,fun) ``` does not print any message, but returns a very rough estimate of the relative error in the computed result.

If `A` is symmetric or Hermitian, then its Schur form is diagonal and `funm` is able to produce an accurate result.

`L = logm(A)` uses `funm` to do its computations, but it can get more reliable error estimates by comparing `expm(L)` with `A`. `S = sqrtm(A)` and `E = expm(A)` use completely different algorithms.

Examples

Example 1. `fun` can be specified using `@`:

• ```F = funm(magic(3),@sin)
```

is the matrix sine of the 3-by-3 magic matrix.

Example 2. The statements

• ```S = funm(X`,`@sin);
C = funm(X`,`@cos);
```

produce the same results to within roundoff error as

• ```E = expm(i*X);
C = real(E);
S = imag(E);
```

In either case, the results satisfy `S*S+C*C = I`, where `I` `=` `eye(size(X)).`

Algorithm

`funm` uses a potentially unstable algorithm. If `A` is close to a matrix with multiple eigenvalues and poorly conditioned eigenvectors, `funm` may produce inaccurate results. An attempt is made to detect this situation and print a warning message. The error detector is sometimes too sensitive and a message is printed even though the the computed result is accurate.

The matrix functions are evaluated using Parlett's algorithm, which is described in [1].

`expm`, `logm`, `sqrtm`, `function_handle` (`@`)