Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**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.**

To compute the determinant of a square matrix numerically, use
the `numeric::det`

function.
For example, compute the determinant of the 5
×5 Pascal matrix:

numeric::det(linalg::pascal(5))

When you use numeric functions, the result can be extremely
sensitive to roundoff errors. For example, the determinant of a Pascal
matrix of any size is 1. However, if you use the `numeric::det`

function to compute the
determinant of a 25×25 Pascal
matrix, you get the following incorrect result:

numeric::det(linalg::pascal(15))

When computing determinants numerically, you can use the `HardwareFloats`

and `SoftwareFloats`

options
to employ the hardware or software float arithmetic, respectively.
(You can use the short names for these options: `Hard`

and `Soft`

.)

When you use the `HardwareFloats`

option, MuPAD^{®} converts
all input data to hardware floating-point numbers, and passes the
data for processing by compiled C code outside of the MuPAD session.
Then, the results get back into the MuPAD session. Hardware arithmetic
often allows you to perform computations much faster than software
arithmetic, which uses the MuPAD kernel for performing computations.

The precision of hardware arithmetic is limited to about 15
digits. By default, the `numeric::det`

function
uses the `HardwareFloats`

option. The function switches
to software arithmetic under one or more of the following conditions:

You use the

`SoftwareFloats`

option or the`MinorExpansion`

option explicitly.The current value of

`DIGITS`

is larger than 15.The input data or computed data involves numbers that are larger than 10

^{308}or smaller than 10^{- 308}. Hardware floats cannot represent such numbers.

The precision of hardware and software arithmetic can differ.
Therefore, the results obtained with the `HardwareFloats`

and `SoftwareFloats`

options
also can differ. For example, compute the determinant of the 25
×25 Pascal matrix using each of the options.
Both numeric results are several orders larger than the correct answer
because of the roundoff errors. However, the result obtained using
software arithmetic is several orders closer to the correct answer:

P := linalg::pascal(25): detP := det(P): float(detP); numeric::det(P, SoftwareFloats); numeric::det(P, HardwareFloats)

Another example of numerically ill-conditioned matrices is the Hilbert matrices. For example, create the 20×20 Hilbert matrix, compute its determinant symbolically, and then approximate the result numerically:

H := linalg::hilbert(15): detH := det(H): float(detH)

Now, use the `numeric::det`

function
to compute the determinant numerically:

numeric::det(H)

The numeric result obtained with the `SoftwareFloats`

option
is closer to the correct result:

numeric::det(linalg::hilbert(15), SoftwareFloats)

To prevent the conversion of input data to floating-point numbers
while using the `numeric::det`

function,
use the `Symbolic`

option. This option allows you
to compute the determinant exactly (without roundoff errors). For
matrices over particular rings and fields, the determinant computed
by `numeric::det`

with
the `Symbolic`

option can differ from the determinant
computed by `det`

.
The reason is that `det`

performs
computations over the component domain of the input matrix. The `numeric::det`

function
with the `Symbolic`

option always performs computations
over the field of arbitrary MuPAD expressions. For example, create
the following matrix over the domain `Dom::IntegerMod(5)`

:

A := Dom::Matrix(Dom::IntegerMod(5))([[1, 2], [3, 4]])

The `det`

function
computes the determinant over the component domain `Dom::IntegerMod(5)`

:

det(A)

The `numeric::det`

function
with the `Symbolic`

option computes the determinant
of the following matrix instead of the original matrix `A`

:

expr(A)

The determinant of this matrix is an integer number:

numeric::det(A, Symbolic)

The `numeric::det`

function
switches to the `Symbolic`

option under one or more
of the following conditions:

You use the

`Symbolic`

option explicitly.The input data contains symbolic objects.

Was this topic helpful?