W3cubDocs

/Octave

28.2 Finding Roots

Octave can find the roots of a given polynomial. This is done by computing the companion matrix of the polynomial (see the compan function for a definition), and then finding its eigenvalues.

roots (c)

Compute the roots of the polynomial c.

For a vector c with N components, return the roots of the polynomial

c(1) * x^(N-1) + … + c(N-1) * x + c(N)

As an example, the following code finds the roots of the quadratic polynomial

p(x) = x^2 - 5.
c = [1, 0, -5];
roots (c)
⇒  2.2361
⇒ -2.2361

Note that the true result is +/- sqrt(5) which is roughly +/- 2.2361.

See also: poly, compan, fzero.

z = polyeig (C0, C1, …, Cl)
[v, z] = polyeig (C0, C1, …, Cl)

Solve the polynomial eigenvalue problem of degree l.

Given an nxn matrix polynomial

C(s) = C0 + C1 s + … + Cl s^l

polyeig solves the eigenvalue problem

(C0 + C1 z + … + Cl z^l) v = 0.

Note that the eigenvalues z are the zeros of the matrix polynomial. z is a row vector with n*l elements. v is a matrix (n x n*l) with columns that correspond to the eigenvectors.

See also: eig, eigs, compan.

compan (c)

Compute the companion matrix corresponding to polynomial coefficient vector c.

The companion matrix is

     _                                                        _
    |  -c(2)/c(1)   -c(3)/c(1)  …  -c(N)/c(1)  -c(N+1)/c(1)  |
    |       1            0      …       0             0      |
    |       0            1      …       0             0      |
A = |       .            .      .         .             .      |
    |       .            .       .        .             .      |
    |       .            .        .       .             .      |
    |_      0            0      …       1             0     _|

The eigenvalues of the companion matrix are equal to the roots of the polynomial.

See also: roots, poly, eig.

[multp, idxp] = mpoles (p)
[multp, idxp] = mpoles (p, tol)
[multp, idxp] = mpoles (p, tol, reorder)

Identify unique poles in p and their associated multiplicity.

The output is ordered from largest pole to smallest pole.

If the relative difference of two poles is less than tol then they are considered to be multiples. The default value for tol is 0.001.

If the optional parameter reorder is zero, poles are not sorted.

The output multp is a vector specifying the multiplicity of the poles. multp(n) refers to the multiplicity of the Nth pole p(idxp(n)).

For example:

p = [2 3 1 1 2];
[m, n] = mpoles (p)
   ⇒ m = [1; 1; 2; 1; 2]
   ⇒ n = [2; 5; 1; 4; 3]
   ⇒ p(n) = [3, 2, 2, 1, 1]

See also: residue, poly, roots, conv, deconv.

© 1996–2018 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/interpreter/Finding-Roots.html