Inverse of a matrix
This functionality does not run in MATLAB.
numeric::inverse(A) returns the inverse of the matrix A.
If no return type is specified via the option ReturnType = t, the domain type of the inverse depends on the type of the input matrix A:
The inverse of a dense matrix of type Dom::DenseMatrix() is a dense matrix of type Dom::DenseMatrix() over the ring of MuPAD® expressions.
For all other matrices of category Cat::Matrix, the inverse is returned as a matrix of type Dom::Matrix() over the ring of MuPAD expressions. This includes input matrices A of type Dom::Matrix(...), Dom::SquareMatrix(...), Dom::MatrixGroup(...) etc.
The option Symbolic should be used if the matrix contains symbolic objects that cannot be converted to floating point numbers.
Without the option Symbolic, all entries of A must be numerical. Floating point arithmetic is used, the working precision is set by the environment variable DIGITS. Exact numerical expressions such as , sin(3) etc. are accepted and converted to floats. If symbolic entries are found in the matrix, numeric::inverse automatically switches to Symbolic, issuing a warning. This warning may be suppressed via the option NoWarning.
Note: Invertibility of the matrix can only be safely detected with exact arithmetic, i.e., using the option Symbolic. See Example 2.
Note: Matrices A of a matrix domain such as Dom::Matrix(..) or Dom::SquareMatrix(..) are internally converted to arrays over expressions via expr(A). Note that Symbolic should be used if the entries cannot be converted to numerical expressions.
Note that 1/A must be used, when the inverse is to be computed over the component domain. See Example 3.
We recommend to use numeric::linsolve or numeric::matlinsolve if a sparse system of linear equations is to be solved. In particular, these routines are more efficient than numeric::inverse for large sparse systems.
numeric::linsolve uses sparse input and output via symbolic equations and features internal sparse arithmetic.
Alternatively, sparse matrices of domain type Dom::Matrix() may be used with numeric::matlinsolve.
Without the option Symbolic, the function is sensitive to the environment variable DIGITS, which determines the numerical working precision.
Numerical matrices can be processed with or without the option Symbolic. In the following, the inverses are returned as arrays because the input matrix is an array:
A := array(1..2, 1..2, [[1, 2], [3, PI]]):
numeric::inverse(A), numeric::inverse(A, Symbolic)
Matrices of category Cat::Matrix are accepted. The inverse is returned as a corresponding matrix:
A := Dom::Matrix()([[2, PI], [0, 1]]): numeric::inverse(A); domtype(%)
The following matrix is not invertible:
A := linalg::hilbert(6): A[6,6] := 5773/63504: A
With exact arithmetic, numeric::inverse detects this fact:
numeric::det(A, Symbolic), numeric::inverse(A, Symbolic)
Due to internal round-off, the matrix is regarded as invertible if float arithmetic is used:
numeric::det(A, HardwareFloats), numeric::inverse(A, HardwareFloats);
With SoftwareFloats, the internal rounding is slightly different and the kernel of the matrix is detected:
numeric::det(A, SoftwareFloats), numeric::inverse(A, SoftwareFloats)
The following matrix has domain components:
A := Dom::Matrix(Dom::IntegerMod(7))([[6, -1], [1, 6]])
Note that numeric::inverse computes the inverse of the following matrix:
The overloaded arithmetic should be used if the inverse is to be computed over the component domain Dom::IntegerMod(7):
The option Symbolic should not be used for float matrices because no internal pivoting is used to stabilize the numerical algorithm:
A := matrix([[1.0/10^20, 1.0], [1.0, 1.0]]): bad = numeric::inverse(A, Symbolic), good = numeric::inverse(A)
We demonstrate the use of hardware floats. Hilbert matrices are notoriously ill-conditioned and difficult to invert with low values of DIGITS. The following results, both with HardwareFloats as well as with SoftwareFloats, are marred by numerical round-off. Consequently, the inverses with and without hardware floats, respectively, differ significantly:
A := linalg::hilbert(10): DIGITS := 10: B1 := numeric::inverse(A, HardwareFloats): B2 := numeric::inverse(A, SoftwareFloats): B1[8, 8] <> B2[8, 8]
norm(B1 - B2)
delete A, B1, B2:
Hard, HardwareFloats, Soft, SoftwareFloats
With Hard (or HardwareFloats), computations are done using fast hardware float arithmetic from within a MuPAD session. Hard and HardwareFloats are equivalent. With this option, the input data are converted to hardware floats and processed by compiled C code. The result is reconverted to MuPAD floats and returned to the MuPAD session.
With Soft (or SoftwareFloats) computations are dome using software float arithmetic provided by the MuPAD kernel. Soft and SoftwareFloats are equivalent. SoftwareFloats is used by default if the current value of DIGITS is larger than 15 and the input matrix A is not of domain type DOM_HFARRAY.
Compared to the SoftwareFloats used by the MuPAD kernel, the computation with HardwareFloats may be many times faster. Note, however, that the precision of hardware arithmetic is limited to about 15 digits. Further, the size of floating-point numbers may not be larger than approximately 10308 and not smaller than approximately 10- 308.
If no HardwareFloats or SoftwareFloats are requested explicitly, the following strategy is used: If the current value of DIGITS is smaller than 16 or if the matrix A is a hardware float array of domain type DOM_HFARRAY, then hardware arithmetic is tried. If this is successful, the result is returned.
If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried.
If the current value of DIGITS is larger than 15 and the input matrix A is not of domain type DOM_HFARRAY, or if one of the options Soft, SoftwareFloats or Symbolic is specified, MuPAD computes the result with its software arithmetic without trying to use hardware floats first.
There may be several reasons for hardware arithmetic to fail:
If neither HardwareFloats nor SoftwareFloats is specified, the user is not informed whether hardware floats or software floats are used.
If HardwareFloats are specified but fail due to one of the reasons above, a warning is issued that the (much slower) software floating-point arithmetic of the MuPAD kernel is used.
Note that HardwareFloats can only be used if all input data can be converted to floating-point numbers.
The trailing digits in floating-point results computed with HardwareFloats and SoftwareFloats may differ.
Prevents the conversion of the input data to floating-point numbers. Exact arithmetic is used. This option overrides HardwareFloats and SoftwareFloats.
This option prevents conversion of the input data to floats. With this option, symbolic entries are accepted.
Without the option Symbolic, numeric::inverse automatically switches to the Symbolic mode with a warning if symbolic coefficients are found. With the option NoWarning, this warning is suppressed. Note, however, that numeric::inverse still uses the symbolic mode for symbolic coefficients, i.e., exact arithmetic without floating-point conversions is used.
Option, specified as ReturnType = t
Depending on the type of the input matrix A, the inverse is returned as a matrix of domain type DOM_ARRAY, DOM_HFARRAY, Dom::Matrix(), or Dom::DenseMatrix(). FAIL is returned if the inverse cannot be computed.
Gaussian elimination with partial pivoting is used. Partial pivoting is switched off by the option Symbolic.