Functional calculus for numerical square matrices
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
p1, p2, …,
numeric::fMatrix(f, A) computes the matrix f(A) with
a function f and
a square matrix A.
If no return type is specified via the option
= d, the domain type of the result depends on the type of
the input matrix
For a dense matrix A of
Dom::DenseMatrix() the result is a dense matrix
Dom::DenseMatrix() over the ring of MuPAD® expressions.
For all other matrices A of
the result is returned as a
Dom::Matrix() over the ring of MuPAD expressions.
This includes input matrices
A of type
The components of A must
not contain symbolic objects which cannot be converted to numerical
Numerical symbolic expressions such as π,
are accepted. They are converted to floats.
When you use
Symmetric/Hermitian and skew/skew Hermitian matrices can always
be diagonalized in a numerically stable way;
reliable numerical results for such matrices.
The procedure f must accept complex floating-point numbers as first argument. It may return arbitrary MuPAD expressions, provided these can be multiplied with floating-point numbers.
… may be numerical or symbolic objects. They must be accepted
f as 2nd argument, 3rd argument etc.
In contrast to the components of A,
numerical symbolic objects such as π,
passed as parameters
… are not converted to floats.
Inversion or exponentiation of a matrix may be realized with
exp, respectively. However,
it is recommended to use the specialized algorithms
Also matrix evaluation of low degree polynomials should be done with
standard matrix arithmetic rather than with
The function is sensitive to the environment variable
which determines the numerical working precision.
We compute the matrix power A100:
A := array(1..2, 1..2, [[2, PI], [exp(-10), 0]]): numeric::fMatrix(x -> x^100, A)
Alternatively, you may use the function
_power which takes the exponent as a
numeric::fMatrix(_power, A, 100)
We compute the square root of a matrix:
A := matrix([[0, 1], [-1, 1]]): B := numeric::fMatrix(sqrt, A)
The small imaginary parts are caused by numerical round-off. We eliminate them by extracting the real parts of the components:
B := map(B, Re)
We verify that
Since A was
passed as a matrix of type
Dom::Matrix(), the matrix B is
also of this type. We may compute the square by the overloaded standard
arithmetic using the operator
delete A, B:
We compute with a symbolic parameter t:
A := array(1..2, 1..2, [[0, 1], [-1, 0]]): numeric::fMatrix(exp@_mult, A, t*PI)
We demonstrate the difference between
The diagonalization of the following matrix is ill-conditioned. The
result is dominated by round-off effects:
A := array(1..3, 1..3, [[10, 1, 1 ], [ 0, 1, 1 ], [ 1, 0, 10^(-14)]]): numeric::fMatrix(ln, A, SoftwareFloats)
numeric::fMatrix(ln, A, HardwareFloats)
In the following case, the round-off effects of
the algorithm think that the matrix cannot be diagonalized. Consequently,
HardwareFloats, however, a result
A := array(1..3, 1..3, [[ 1 , 1 , 1 ], [ 0 , 1 , 1 ], [ 10^(-30), 0 , 10^(-30)]]): numeric::fMatrix(ln, A, SoftwareFloats)
numeric::fMatrix(ln, A, HardwareFloats)
A procedure representing a scalar function or , where P is a set of parameters
Arbitrary MuPAD objects accepted by f as additional input parameters
Compared to the
If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried.
If the current value of
There may be several reasons for hardware arithmetic to fail:
Option, specified as
Depending on the type of the input matrix
the matrix f(A) is
returned as a matrix of type
If the algorithm thinks that
A is not diagonalizable,
A numerical diagonalization A = X diag(λ1, λ2, …) X- 1 is computed. The columns of X are the (right) eigenvectors of A, the diagonal entries λ1, λ2, … are the corresponding eigenvalues. The function f is mapped to the eigenvalues, the matrix result is computed by
The eigenvector matrix X may
be obtained via
The condition number of the eigenvector matrix is a measure indicating how well conditioned the diagonalization of the matrix A is. If this number is larger than 10DIGITS, then not a single digit of the diagonalization data is trustworthy.
numeric::fMatrix(exp, A) corresponds