r = roots(p)
r = roots( returns
the roots of the polynomial represented by
a column vector. Input
p is a vector containing
coefficients, starting with the coefficient of xn.
A coefficient of
0 indicates an intermediate power
that is not present in the equation. For example,
p = [3
2 -2] represents the polynomial .
roots function solves polynomial equations
of the form .
Polynomial equations contain a single variable with nonnegative exponents.
Solve the equation .
Create a vector to represent the polynomial, then find the roots.
p = [3 -2 -4]; r = roots(p)
r = 1.5352 -0.8685
Polynomial coefficients, specified as a vector. For example,
[1 0 1] represents the polynomial ,
and the vector
[3.13 -2.21 5.99] represents the
For more information, see Create and Evaluate Polynomials.
Complex Number Support: Yes
to obtain a polynomial from its roots:
p = poly(r).
poly function is the inverse of the
to find the roots of nonlinear equations. While the
works only with polynomials, the
is more broadly applicable to different types of equations.
roots function considers
be a vector with
n+1 elements representing the
degree characteristic polynomial of an
The roots of the polynomial are calculated by computing the eigenvalues
of the companion matrix,
A = diag(ones(n-1,1),-1); A(1,:) = -p(2:n+1)./p(1); r = eig(A)
The results produced are the exact eigenvalues of a matrix within
roundoff error of the companion matrix,
this does not mean that they are the exact roots of a polynomial whose
coefficients are within roundoff error of those in