# linalg::minpoly

Minimal polynomial of a matrix

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```linalg::minpoly(`A`, `x`)
```

## Description

`linalg::minpoly(A, x)` computes the minimal polynomial of the square matrix A in x, i.e., the monic polynomial of lowest degree annihilating the matrix A.

The minimal polynomial of `A` divides the characteristic polynomial of `A`, by Cayley-Hamilton theorem.

If the matrix is defined over `Dom::Float`, then due to numerical errors the computed polynomial can have a degree higher than the dimension of the matrix. In such cases, `linalg::minpoly` returns the value `FAIL`. See Example 3.

The component ring of `A` must be a field, i.e., a domain of category `Cat::Field`.

## Examples

### Example 1

We define the following matrix over the rational numbers:

```A := Dom::Matrix(Dom::Rational)( [[0, 2, 0], [0, 0, 2], [2, 0, 0]] )```

The minimal polynomial of the matrix A in the variable x is then given by:

`delete x: linalg::minpoly(A, x)`

In this case, the minimal polynomial is in fact equal to the characteristic polynomial of A:

`linalg::charpoly(A, x)`

### Example 2

The minimal polynomial of the matrix:

`B := matrix([[0, 1, 0], [0, 0, 0], [0, 0, 0]])`

is a polynomial of degree 2:

`m := linalg::minpoly(B, x)`

The characteristic polynomial of B has degree 3 and is divided by the minimal polynomial of B:

`p := linalg::charpoly(B, x)`

`p / m`

### Example 3

For the following example, MuPAD® is not able to compute the minimal polynomial, and thus `FAIL` is returned:

```C := Dom::Matrix(Dom::Float)([ [7, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 2, 0, 0, 0], [1, 2, 3, 0, 0], [1, 2, 3, 4, 7] ])```

`delete x: linalg::minpoly(C, x)`
```Warning: Cannot compute the minimal polynomial. [linalg::minpoly] ```

In fact, for this example MuPAD is not able to check for zero equivalence during Gaussian elimination and therefore chose a wrong pivot element.

If you perform the computation over the coefficient domain`Dom::ExpressionField``(normal)` instead, then in most cases the minimal polynomial can be computed:

```C := matrix([ [7, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 2, 0, 0, 0], [1, 2, 3, 0, 0], [1, 2, 3, 4, 7] ])```

`linalg::minpoly(C, x)`

However, in general this problem regarding zero recognition cannot be avoided.

## Parameters

 `A` A square matrix of a domain of category `Cat::Matrix` `x` An indeterminate

## Return Values

Polynomial of the domain `Dom::DistributedPolynomial([x],R)`, where `R` is the component ring of `A`, or the value `FAIL`.