GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • WOLFRAM
  • Products
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App
  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs
  • Wolfram AI Ecosystem

This view

  • Original page
  • New address

GeezerVison is showing reference.wolfram.com — MatrixFunction: Apply a general function to a matrix—Wolfram Documentation

MatrixFunction[f,m]

gives the matrix generated by the scalar function f at the matrix argument m.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Basic Uses  
Special Matrices  
Options  
Method  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Tech Notes
Related Guides
History
Cite this Page

MatrixFunction

MatrixFunction[f,m]

gives the matrix generated by the scalar function f at the matrix argument m.

Details and Options

  • A matrix function transforms a matrix to another matrix. For convergent power series, MatrixFunction[f,m] effectively evaluates the power series for the function f with ordinary powers replaced by matrix powers. »
  • The function f should be a unary differentiable or symbolic function.
  • MatrixFunction works only on square matrices.
  • MatrixFunction can be used on SparseArray objects and structured arrays.
  • The following option can be given:
  • Method Automaticmethod to use
  • Possible values for the option Method include:
  • Automaticautomatic selection
    "Jordan"Jordan decomposition
    "Schur"Schur decomposition with block Parlett recursion
    "SpectralBasis"spectral method for exact matrices »
  • The default setting of Method->Automatic uses the Schur decomposition for inexact numerical matrices and, based on matrix contents, selects between the Jordan decomposition and the spectral basis method for exact and symbolic matrices.
  • The "Schur" method can be specified with method options mopts by Method->{"Schur",mopts}. The following method options can be given:
  • "Balanced"Falsewhether to balance the input matrix before doing the Schur decomposition
    "BlockSeparationDelta"Automaticmaximum separation between adjacent eigenvalues in a single Parlett block

Examples

open all close all

Basic Examples  (3)

Compute the square root of a symbolic matrix:

Wolfram Language code: MatrixFunction[Sqrt, {{a, 1}, {0, b}}]

Verify that it is, indeed, a square root:

Wolfram Language code: %.%//Simplify

Note that this is different from simply computing the square root of each entry:

Wolfram Language code: Sqrt[{{a, 1}, {0, b}}]

Compute the logarithm of a 3×3 matrix m:

Wolfram Language code: m = {{2., 2., 1.}, {4., 6., 4.}, {3., 6., 8.}}; MatrixFunction[Log, m]

Verify that the exponential of the result is the original matrix:

Wolfram Language code: MatrixExp[%] == m

Compute a matrix polynomial, specifying the polynomial as a pure function:

Wolfram Language code: MatrixFunction[x |-> x^5 + 2x^2 + 1, {{a, 0}, {1, b}}]

Scope  (11)

Basic Uses  (7)

Compute the matrix sine and cosine of a machine-precision matrix:

Wolfram Language code: m = {{1., 1., 0.}, {0., 1., 0.}, {0., 0., 2.}};
Wolfram Language code: cosm = MatrixFunction[Cos, m]
Wolfram Language code: sinm = MatrixFunction[Sin, m]

Test the matrix identity :

Wolfram Language code: sinm.sinm + cosm.cosm == IdentityMatrix[3]

Compute the matrix sine for a complex matrix:

Wolfram Language code: MatrixFunction[Sin, {{1., 2 + I}, {3 + I, 1}}]//MatrixForm

Compute the square root of an exact matrix:

Wolfram Language code: MatrixFunction[Sqrt, {{(5 π/18), (2 π/9)}, {(4 π/9), (π/18)}}]//Simplify

Use 20-digit-precision arithmetic to compute the matrix function of a logarithm of a polynomial:

Wolfram Language code: m = N[{{1, 1 / 2, 1 / 3, 1 / 4}, {0, 1, 1 / 3, 1 / 4}, {0, 0, 1, 1 / 4}, {0, 0, 0, 1}}, 20];
Wolfram Language code: MatrixFunction[Log[1 + 2# + 3#^2]&, m]

Compute the matrix sine of a symbolic diagonal matrix:

Wolfram Language code: MatrixFunction[Sin, {{a, 0}, {0, b}}]

Compute the matrix tangent of a symbolic non-diagonal matrix:

Wolfram Language code: MatrixFunction[Tan, {{a, 0}, {1, b}}]

Compute a matrix function with a symbolic scalar function:

Wolfram Language code: MatrixFunction[f, {{1, 2}, {0, 1}}]//Simplify

Use a symbolic matrix with a symbolic scalar function:

Wolfram Language code: MatrixFunction[f, {{0, a}, {b, 0}}]//Simplify

Applying a function to a machine-precision matrix is efficient:

Wolfram Language code: m = RandomReal[{0, 1}, {500, 500}];
Wolfram Language code: MatrixFunction[Log, m]; //AbsoluteTiming

Special Matrices  (4)

Computing a matrix function with a sparse matrix generally produces a normal matrix:

Wolfram Language code: SparseArray[{{i_, i_} -> -2., {i_, j_} /; Abs[i - j] == 1 -> 1.}, {6, 6}]
Wolfram Language code: MatrixFunction[Exp[-#^2]&, %]//MatrixForm

Compute a matrix polynomial of a structured array:

Wolfram Language code: SymmetrizedArray[{{1, 1} -> 3.5, {2, 2} -> 1.2, {3, 1} -> -5.3}, {3, 3}, Symmetric[All]]
Wolfram Language code: MatrixFunction[#^3 + 2 #^1 + 3 #&, %]//MatrixForm

Applying a matrix function to an identity matrix only changes the value of the diagonal elements:

Wolfram Language code: MatrixFunction[Exp, IdentityMatrix[3]]//MatrixForm
Wolfram Language code: MatrixFunction[Log, IdentityMatrix[3]]//MatrixForm

More generally, a function of any diagonal matrix is the function applied to its diagonal elements:

Wolfram Language code: MatrixFunction[Log, DiagonalMatrix[{a, b, c}]]

Compute the square of HilbertMatrix to 20-digit precision:

Wolfram Language code: N[MatrixFunction[Sqrt, HilbertMatrix[2]], 20]//MatrixForm

Options  (5)

Method  (5)

The method "Jordan" can work with exact and inexact matrices:

Wolfram Language code: MatrixFunction[Sin[# π]&, {{1 / 2, 1 / 3}, {1 / 3, 1 / 4}}, Method -> "Jordan"]//Simplify
Wolfram Language code: MatrixFunction[Sin[# π]&, {{1. / 2., 1. / 3.}, {1. / 3., 1. / 4.}}, Method -> "Jordan"]

The method "Schur" works only with inexact (machine- and arbitrary-precision) matrices:

Wolfram Language code: MatrixFunction[Sin[# π]&, {{1 / 2, 1 / 3}, {1 / 3, 1 / 4}}, Method -> "Schur"]
Wolfram Language code: MatrixFunction[Sin[# π]&, {{1. / 2., 1. / 3.}, {1. / 3., 1. / 4.}}, Method -> "Schur"]

If many eigenvalues are very close, they are put in a diagonal-block submatrix, which may become large; computations are then more expensive and convergence may be slow:

Wolfram Language code: m = (⁠| | | | | ------ | ------ | ------ | | 0.0003 | 100. | 1. | | 0 | 0.0002 | 100. | | 0 | 0 | 0.0001 |⁠); f = (1 - #) / Sqrt[1 - #^2]&;
Wolfram Language code: AbsoluteTiming[m1 = MatrixFunction[f, m]]

A smaller value for "BlockSeparationDelta" reduces the diagonal block size and also speeds convergence:

Wolfram Language code: AbsoluteTiming[m2 = MatrixFunction[f, m, Method -> {"Schur", "BlockSeparationDelta" -> 10^-6}]]

But the result may be much less accurate:

Wolfram Language code: mfinv = Function[Module[{id = IdentityMatrix[Length[#]]}, Inverse[id + #.#].(id - #.#)]]; {Norm[mfinv[m1] - m], Norm[mfinv[m2] - m]}

When an input matrix is poorly balanced (containing terms of very different magnitudes), balancing may improve the result:

Wolfram Language code: m = {{1000., 0, 0, 0, 0.3, 0, -1000}, {0, 0.1, 0, 0.2, 0.4, -1000, 3000}, {0, 0, 2000., 0, 0.3, 0.2, -1000}, {0, 0, 0, 1., 0, -1000, 0}, {0, 1000, 0, 0, 0.3, 0.1, 0}, {0, 0, 0, 0, 0, 0.2, -0.3}, {100, 0, 0, 0, 0, 0, 1.}}; m0 = MatrixFunction[Sqrt, m, Method -> {"Schur", "Balanced" -> True}]; m1 = MatrixFunction[Sqrt, m, Method -> "Schur"]; {Norm[MatrixPower[m0, 2] - m], Norm[MatrixPower[m1, 2] - m]}

When it is applicable, "SpectralBasis" can be orders of magnitude faster than "Jordan":

Wolfram Language code: mat = {{0, 0, 0, -2, -2, 0, 2, -1}, {0, -2, 4, 2, -2, 2, 5, 2}, {4, 0, 0, 2, 4, -3, -2, 6}, {-2, -2, 2, -2, -1, -4, 0, 2}, {0, -2, 2, -1, 0, 2, -2, -2}, {0, -4, 1, 2, -2, 2, -4, 0}, {0, 1, 0, 0, 2, 0, -4, 0}, {-1, 0, -2, 0, 0, 0, -4, -2}}; AbsoluteTiming[mexp1 = MatrixFunction[Exp, mat, Method -> "SpectralBasis"];]
Wolfram Language code: AbsoluteTiming[mexp2 = MatrixFunction[Exp, mat, Method -> "Jordan"];]

It can also produce much simpler results:

Wolfram Language code: AbsoluteTiming[LeafCount[mexp1]]
Wolfram Language code: AbsoluteTiming[LeafCount[mexp2]]

The two results are equal, however:

Wolfram Language code: AbsoluteTiming[Chop[N[mexp1 - mexp2]]]

The method is chosen automatically for matrices of exact numbers, where it excels:

Wolfram Language code: MatrixQ[mat, NumberQ] && Precision[mat] == Infinity && mexp1 === MatrixFunction[Exp, mat]

Applications  (5)

Find the second inverse matrix power applied to a particular vector:

Wolfram Language code: m = RandomReal[{1, 2}, {10, 10}]; b = ConstantArray[1., 10];
Wolfram Language code: MatrixFunction[#^-2&, m].b

This is a more efficient way of computing :

Wolfram Language code: minv = LinearSolve[m]; Nest[minv, b, 2]

Show that a matrix is a root of its characteristic polynomial:

Wolfram Language code: m = {{0, 0, 0, 0, 1}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, {0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}};
Wolfram Language code: p = CharacteristicPolynomial[m, #]
Wolfram Language code: MatrixFunction[Evaluate[p]&, m] == ConstantArray[0, Dimensions[m]]

The solution of , , for a scalar symbol is given with:

Wolfram Language code: DSolve[{D[y[t], {t, 2}] + A y[t] == 0, y[0] == y0[0], y'[0] == y0'[0]}, y, t]

If is a matrix, the solution can be computed using matrix functions in the scalar solution:

Wolfram Language code: A = -{{0, 1, 0}, {1 / 3, 1, 0}, {1, 0, 1}}//N; y0[t_] := {t, Sqrt[1 + t], 1 + t}
Wolfram Language code: sqA = MatrixFunction[Sqrt, A]; y[t_ ? NumericQ] := MatrixFunction[Cos, t sqA].y0[0] + Inverse[sqA].MatrixFunction[Sin, t sqA].y0'[0];
Wolfram Language code: Plot[y[t], {t, 0, 1}]

Find the matrix that satisfies :

Wolfram Language code: m = RandomReal[{0, 1}, {6, 6}];
Wolfram Language code: f[x_ ? MatrixQ] := MatrixFunction[# + Sin[#]&, x];
Wolfram Language code: sol = FindRoot[f[x] == m, {x, IdentityMatrix[Length[m]]}]; MatrixForm[x /. sol]
Wolfram Language code: f[x /. sol] - m//Chop

Confirm the formula for a Jordan matrix consisting of a single chain for the following matrix :

Wolfram Language code: MatrixForm[j = λ IdentityMatrix[5] + DiagonalMatrix[{1, 1, 1, 1}, 1, 5]]
Wolfram Language code: MatrixFunction[f, j]//MatrixForm

Properties & Relations  (11)

Using the function 1& returns an identity matrix:

Wolfram Language code: MatrixFunction[1&, {{1, 2}, {3, 4}}]//Simplify

Using the function 1/#& is the same as using Inverse:

Wolfram Language code: MatrixFunction[1 / #&, {{1, 1}, {1, 2}}] == Inverse[{{1, 1}, {1, 2}}]

Using a function that is a power is equivalent to using MatrixPower:

Wolfram Language code: MatrixFunction[#^n&, {{0, 0, 1}, {0, 2, 0}, {-1, 0, 0}}] == MatrixPower[{{0, 0, 1}, {0, 2, 0}, {-1, 0, 0}}, n]

MatrixFunction[Exp,m] is essentially equivalent to MatrixExp[m]:

Wolfram Language code: m = RandomReal[1, {3, 3}]; MatrixFunction[Exp, m] == MatrixExp[m]

MatrixFunction effectively uses the power series, with Power replaced by MatrixPower:

Wolfram Language code: a = {{1, -(1/6)}, {1, (1/6)}};
Wolfram Language code: MatrixFunction[Sqrt, a] == Sum[(Derivative[k][Sqrt][1]/k!) MatrixPower[a - IdentityMatrix[2], k], {k, 0, ∞}]
Wolfram Language code: MatrixFunction[Log, a] == Sum[(Derivative[k][Log][1]/k!) MatrixPower[a - IdentityMatrix[2], k], {k, 0, ∞}]

Just as , MatrixExp[MatrixFunction[Log,m]] equals m:

Wolfram Language code: m = {{0, 0, 1}, {0, 2, 0}, {-1, 0, 0}}; m == MatrixExp[MatrixFunction[Log, m]]

If m is diagonal, MatrixFunction[f,m] merely applies f to each element of the diagonal of m:

Wolfram Language code: MatrixFunction[Cosh, DiagonalMatrix[{a, b, c}]]//MatrixForm

If m is upper triangular, MatrixFunction[f,m] is also upper triangular:

Wolfram Language code: m = UpperTriangularize[RandomInteger[9, {5, 5}]]; UpperTriangularMatrixQ[MatrixFunction[Tanh, m]]

The analogous statement holds for lower-triangular matrices:

Wolfram Language code: m = LowerTriangularize[RandomInteger[9, {5, 5}]]; LowerTriangularMatrixQ[MatrixFunction[Tanh, m]]

If is diagonalizable with and the eigenvectors are well conditioned, then :

Wolfram Language code: m = RandomReal[1, {3, 3}];
Wolfram Language code: {d, vt} = Eigensystem[m]
Wolfram Language code: v = Transpose[vt]; v.DiagonalMatrix[Sin[Cos[d]]].Inverse[v] - MatrixFunction[Sin[Cos[#]]&, m]//Chop

can be computed from the JordanDecomposition as v.f(j).TemplateBox[{v}, Inverse]:

Wolfram Language code: m = {{2, 0, 0, 0}, {0, 1, 0, 0}, {1, -1, 1, 0}, {1, -1, 1, 1}}; {v, j} = JordanDecomposition[m]; MatrixFunction[Sqrt, m] == v.MatrixFunction[Sqrt, j].Inverse[v]

Moreover, is zero except in upper-triangular blocks delineated by s in the superdiagonal:

Wolfram Language code: MatrixForm /@ {j, MatrixFunction[Sqrt, j]}

A matrix is a root of its characteristic polynomial:

Wolfram Language code: m = RandomInteger[2, {3, 3}]
Wolfram Language code: polyf = Function[Evaluate[CharacteristicPolynomial[m, #]]]
Wolfram Language code: MatrixFunction[polyf, m]//Simplify

Possible Issues  (4)

The scalar function can have symbolic derivatives for exact or symbolic matrices:

Wolfram Language code: F[x_ ? NumericQ] := Sqrt[x]; MatrixFunction[F, {{1, 1, 0}, {0, 1, 1}, {0, 0, 1}}]
Wolfram Language code: MatrixFunction[F, {{1, 1, 0}, {0, 1, 1}, {0, 0, 1}}//N]

Compare with this example:

Wolfram Language code: F[x_] := Sqrt[x]; MatrixFunction[F, {{1, 1, 0}, {0, 1, 1}, {0, 0, 1}}]

MatrixFunction does not work with non-differentiable functions such as Abs:

Wolfram Language code: MatrixFunction[Abs, {{1., 1., 0.}, {0., 1., 1.}, {0., 0., 1.}}]

It will return a matrix function for an exact input matrix, but the result is meaningless because Abs does not have a first or second derivative:

Wolfram Language code: MatrixFunction[Abs, {{1, 1, 0}, {0, 1, 1}, {0, 0, 1}}]

MatrixFunction does not return a result when the scalar function or any of its initial derivatives are not defined at matrix eigenvalues:

Wolfram Language code: MatrixFunction[Sqrt[1 - #]&, {{1, 1, 0}, {0, 1, 1}, {0, 0, 1}}]
Wolfram Language code: MatrixFunction[Sqrt[1 - #]&, {{1., 1., 0.}, {0., 1., 1.}, {0., 0., 1.}}]

The scalar function f has poles (singularities) at 1, 2, and 3:

Wolfram Language code: f = 1 / Apply[Times, (# - Range[3])]&;

If a scalar function is not analytic and a matrix eigenvalue is close to a function pole, the resulting matrix is usually incorrect:

Wolfram Language code: m = {{-2.131558166676987, -2.937833681080357, -0.995639204939471}, {4.991469442950794, 5.743899123162778, 1.4428901292047926}, {1.621158931412957, 1.1503162105039664, 2.387659043514208}}; Eigenvalues[m]
Wolfram Language code: mf = MatrixFunction[f, m]

Neat Examples  (1)

Visualize different sines of a cross matrix formed from the identity matrix and its reverse:

Wolfram Language code: A = IdentityMatrix[20] + (Reverse /@ IdentityMatrix[20]) + 1 / 20RandomReal[{0, 1}, {20, 20}]; ListAnimate[MatrixPlot[MatrixFunction[Sin, #]]& /@ Table[i A, {i, 1, 20}]]

See Also

MatrixExp  MatrixLog  MatrixPower  Inverse  JordanDecomposition  Eigensystem  SchurDecomposition

Function Repository: MatrixPolynomial  NEigenvalueSumGradient

Tech Notes

    ▪
  • Basic Matrix Operations
  • ▪
  • Vectors and Matrices

Related Guides

    ▪
  • Matrix Operations
  • ▪
  • Matrix Decompositions
  • ▪
  • Symbolic Vectors, Matrices and Arrays

History

Introduced in 2012 (9.0) | Updated in 2014 (10.0) ▪ 2026 (15.0)

Wolfram Research (2012), MatrixFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixFunction.html (updated 2026).

Text

Wolfram Research (2012), MatrixFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixFunction.html (updated 2026).

CMS

Wolfram Language. 2012. "MatrixFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/MatrixFunction.html.

APA

Wolfram Language. (2012). MatrixFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixFunction.html

BibTeX

@misc{reference.wolfram_2026_matrixfunction, author="Wolfram Research", title="{MatrixFunction}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixFunction.html}", note=[Accessed: 12-November-2026]}

BibLaTeX

@online{reference.wolfram_2026_matrixfunction, organization={Wolfram Research}, title={MatrixFunction}, year={2026}, url={https://reference.wolfram.com/language/ref/MatrixFunction.html}, note=[Accessed: 12-November-2026]}

Top
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.