Main Content

Polynomial roots

Syntax

Description

example

r = roots(p)returns the roots of the polynomial represented bypas a column vector. Inputpis a vector containingn+1polynomial coefficients, starting with the coefficient ofxn。A coefficient of0indicates an intermediate power that is not present in the equation. For example,p = [3 2 -2]represents the polynomial 3 x 2 + 2 x 2

function solves polynomial equations of the form p 1 x n + 。。。 + p n x + p n + 1 = 0 。Polynomial equations contain a single variable with nonnegative exponents.

Examples

collapse all

Solve the equation 3 x 2 - 2 x - 4 = 0

Create a vector to represent the polynomial, then find the roots.

p = [3 -2 -4]; r = roots(p)
r =2×11.5352 -0.8685

Solve the equation x 4 - 1 = 0

Create a vector to represent the polynomial, then find the roots.

p = [1 0 0 0 -1]; r = roots(p)
r =4×1复合物-1.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 - 1.0000i 1.0000 + 0.0000i

Input Arguments

collapse all

Polynomial coefficients, specified as a vector. For example, the vector[1 0 1]represents the polynomial x 2 + 1 , and the vector[3.13 -2.21 5.99]represents the polynomial 3.13 x 2 2.21 x + 5.99

For more information, seeCreate and Evaluate Polynomials

Data Types:single|double
Complex Number Support:Yes

Tips

  • Use thepolyfunction to obtain a polynomial from its roots:p = poly(r)。这polyfunction is the inverse of thefunction.

  • Use thefzerofunction to find the roots of nonlinear equations. While thefunction works only with polynomials, thefzerofunction is more broadly applicable to different types of equations.

Algorithms

功能考虑p成为与n+1elements representing thenth degree characteristic polynomial of ann-by-nmatrix,A。这根of the polynomial are calculated by computing the eigenvalues of the companion matrix,A

A = diag(ones(n-1,1),-1); A(1,:) = -p(2:n+1)./p(1); r = eig(A)

这results produced are the exact eigenvalues of a matrix within roundoff error of the companion matrix,A。However, this does not mean that they are the exact roots of a polynomial whose coefficients are within roundoff error of those inp

Extended Capabilities

版本历史

在R2006a之前引入