Navigation

Operators and Keywords

Function List:

C++ API

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

Package: octave