Scope (9)
Arbitrary differentiable functions of a matrix can be computed provided that the function is well behaved on the matrix eigenvalues:
Check that the answer is correct:
Compute a 10-th power of matrix:
Check that the computation is correct:
A defective matrix:
Compute its logarithm:
Check that computation is correct:
This matrix is not diagonalizable:
A 2 dimensional matrix:
Compute a composition where the second function inverts the first:
A matrix function of small matrix can yield a long result:
For a multivalued function (for example, fractional power, inverse trigonometric, etc) a single matrix is returned:
A check:
ComputeMatrixFunction is implemented to handle defective (nondiagonalizable) matrices:
The matrix is defective:
So the minimal polynomial of this matrix has a factor of nontrivial multiplicity:
The minimal polynomial is a polynomial of lowest degree that annihilates the matrix:
Compute the exponential of this matrix:
Check the size:
Symbolic matrices can be input as well:
The minimal polynomial has roots with multiplicity greater that one, i.e. the matrix is defective:
Since minimal polynomial was already computed, we can help ComputeMatrixFunction by providing a computed matrix polynomial:
Compute minimal polynomial for the matrix input*t:
Check expOfMatrix using the property
of the exponential function to confirm the identity:
ComputeMatrixFunction will not work with sparse arrays/structures. Nevertheless, it can deal with larger matrices than MatrixFunction:
The matrix is non-diagonalizable:
Inverse trigonometric functions of a matrix are multi-valued; ComputeMatrixFunction returns only one of them:
Verify the huge symbolic result numerically by computing the Sin function:
Options (21)
MinimalPolynomial (4)
By default the minimal polynomial of matrix is computed using the primitive algorithm described in MatrixMinimalPolynomial; one can instead have the minimal polynomial computed externally.
Give a matrix:
The computed minimal polynomial should be provided as a pure function:
We can use it inside ComputeMatrixFunction:
MatrixFunction returns the same result faster:
FunctionDomain (5)
An input matrix:
Compute the matrix exponential in the (default) complex domain:
After numerical evaluation we see that negligible imaginary parts are present:
Compute the same function in the real domain:
Numerical evaluation now shows no imaginary numeric fuzz:
OutputSpectralBasis (12)
The spectral basis1 can be used to compute matrix functions. We illustrate this below, using it to replicate the computation of ComputeMatrixFunction.
Input a matrix:
One can compute a given function of matrix along with the generalized spectral basis using option "OutputSpectralBasis"→True:
The generalized spectral basis1 is presented as a list of the form {r,plist} where r is a root of the minimal polynomial and plist is a list of polynomials with length equal to the root multiplicity:
Compute the minimal polynomial:
We see that root -1 has multiplicity 2 so the spectral basis for this root contains two polynomials:
Once the spectral basis is known one can compute the matrix function in the following way. For an eigenvalue of multiplicity n we compute derivatives zero through n-1. Since maximal root multiplicity is 2, the zeroth and first derivatives suffice to handle all eigenvalues:
Now compute the following sum:
First compute the diagonal part of matrix:
Then the off-diagonal part:
Compute matrix powers up the degree of answerCommutativeVar (7):
After replacing formal variable x by the matrix (and similar for powers) we obtain the final answer:
Check that it coincides with previously computed exponent of matrix:
The manually computed matrix function is considerably simpler due to manual simplification of the generalized spectral basis polynomials. Moreover, other functions of the same matrix can be computed using the same generalized spectral basis, so one can compute multiple function computation of the same matrix.
Properties and Relations (2)
Define a matrix:
An arbitrary polynomial p for which p(A)=0, for example the characteristic polynomial, can be provided as a pure function:
Also compute minimal polynomial:
Compute the product of the characteristic and minimal polynomials:
Computation time increases with the degree of provided polynomial, since higher matrix powers get computed:
ComputeMatrixFunction is similar to the built-in MatrixFunction but often yields a less complicated result than in a fraction of time:
Compare with MatrixFunction:
Numerical comparison of both results up to 100 digits takes over 10 minutes, so instead compare an arbitrary element (1,3):
Possible Issues (2)
A noninvertible matrix:
If the given function is not defined at matrix eigenvalues then the computation will fail:
We can determine a problem by inserting formal function f:
The algorithm tries to evaluate function and it's derivatives at points 0 and 2:
It is clear that the attempt to compute reciprocals 1/eigval at 0 produced the error.
ComputeMatrixFunction, like MatrixFunction, does not work with non-differentiable functions such as Abs:
The result is meaningless because Abs does not have a first or second derivative.