funm
- :
F =funm(A, fun)¶ - :
F =funm(A, fun, options)¶ - :
F =funm(A, fun, options, p1, …)¶ - :
[F, exitflag] =funm(…)¶ - :
[F, exitflag, output] =funm(…)¶ -
Apply a scalar function to a square matrix.
The matrix function is defined through the Taylor series of fun, which must converge everywhere, and is computed with a Schur decomposition: the eigenvalues are grouped into clusters, the function is evaluated on each diagonal block of the reordered Schur form by a Taylor expansion, and the off-diagonal blocks are recovered from Sylvester equations.
fun may be a function handle or a function name. For a general function it is called as
fun (x, k)and must return the k-th derivative of the function at every element of x. The handles@exp,@log,@sin,@cos,@sinhand@coshare recognised and need no derivative argument, sofunm (A, @cos)works as is.sqrtmis the right tool for matrix square roots; for the matrix exponentialexpmis usually the better choice, althoughfunm (A, @exp)is available.options is a structure that controls the amount of diagnostic output and the tuning of the algorithm. Field names are matched without regard to case. The recognised fields are:
DisplayHow much to report while working. Either one of the strings
"off"(the default),"on"or"verbose", or a number from0(silent) to5(everything). At"verbose", or a number of3or more, the eigenvalues and their clusters are also plotted.TolBlkPositive tolerance that decides when two eigenvalues belong to the same cluster. Default
0.1.TolTayPositive tolerance for stopping the Taylor expansion of a block. Default
eps.MaxTermsLargest number of Taylor terms to use for one block. Default
250.MaxSqrtFor the logarithm only: the largest number of square roots taken while reducing a block before its series is summed. Default
100.OrdA vector with one entry per row of A that fixes the clustering by hand instead of letting
TolBlkdecide.
Any further arguments p1, … are appended to every call of fun.
The second output exitflag is
0when every Taylor expansion converged and1when at least one did not, in which case F may still be usable.The third output output is a structure with these fields (MATLAB R2026a):
termsThe number of Taylor terms used for each block, or for the logarithm the number of square roots taken for each block of order greater than 2.
indCell array of index vectors; block
(i, j)of the reordered Schur factor isT(output.ind{i}, output.ind{j}).
When the Schur factor is already diagonal no reordering takes place:
termsis all ones andindlists each index on its own.Example: the sine of a symmetric matrix agrees with its spectral decomposition.
A = [2, 1; 1, 2]; # eigenvalues 1 and 3 [V, D] = eig (A); norm (funm (A, @sin) - V * diag (sin (diag (D))) / V) ⇒ ans is of the order of eps
Because
exp (i*X) = cos (X) + i sin (X)holds for matrices too,real (expm (i*X))andimag (expm (i*X))reproducefunm (X, @cos)andfunm (X, @sin)up to rounding.The algorithm follows P. I. Davies and N. J. Higham, "A Schur-Parlett algorithm for computing matrix functions", SIAM J. Matrix Anal. Appl. 25(2), 2003, and chapter 9 of N. J. Higham, Functions of Matrices, SIAM 2008.