compan

Companion matrix of a polynomial.

Category: Mathematics > Elementary Math

Syntax

A = compan(u)

Returns the companion matrix of the polynomial whose coefficients are in u.

Description

The first row of A is -u(2:end) / u(1) and the subdiagonal holds ones. The eigenvalues of A are the roots of the polynomial, which is how roots finds them. For u = [1 2 3] the result is [-2 -3; 1 0].

Input arguments

u
Vector of polynomial coefficients, highest power first. The first entry must be nonzero.

Output arguments

A
Square matrix of size numel(u) - 1.

Example

Roots through eigenvalues

u = [1 -3 2];
A = compan(u)
eig(A)
Output
A = 2×2

     3    -2
     1     0
ans = 2×1

    1.0000
    2.0000

See also

roots poly eig polyval