# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# `linalg`::`charpoly`

Characteristic polynomial of a matrix

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

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

## Description

`linalg::charpoly(A, x)` computes the characteristic polynomial of the matrix A. The characteristic polynomial of a n×n matrix is defined by , where In denotes the n×n identity matrix.

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

## Examples

### Example 1

We define a matrix over the rational numbers:

`A := Dom::Matrix(Dom::Rational)([[1, 2], [3, 4]])`

Then the characteristic polynomial pA(x) is given by:

`linalg::charpoly(A, x)`

It is of the domain type:

`domtype(%)`

### Example 2

We define a matrix over 7:

`B := Dom::Matrix(Dom::IntegerMod(7))([[1, 2], [3, 0]])`

The characteristic polynomial pB(x) of `B` is given by:

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

We compute the zeros of pB(x), i.e., the eigenvalues of the matrix `B`:

`solve(p)`

## Parameters

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

## Return Values

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

## References

Reference: Jounaidi Abdeljaoued, The Berkowitz Algorithm, Maple and Computing the Characteristic Polynomial in an Arbitrary Commutative Ring, MapleTech Vol 4 No 3, pp 21-32, Birkhäuser, 1997.

## Algorithms

`linalg::charpoly` implements Hessenberg's algorithm to compute the characteristic polynomial of a square matrix A. See: Henri Cohen: A Course in Computational Algebraic Number Theory, GTM 138, Springer Verlag.

This algorithm works for any field and requires only O(n3) field operations, in contrast to O(n4) when computing the determinant of the characteristic matrix of A.

Since the size of the components of A in intermediate computations of Hessenberg's algorithm can swell extremely, it is only applied for matrices over `Dom::Float` and `Dom::IntegerMod`.

For any other component ring, the characteristic polynomial is computed using the Berkowitz algorithm.