Polynomial with specified roots or characteristic polynomial
Characteristic Polynomial from Eigenvalues
Calculate the eigenvalues of a matrix,
A = [1 8 -10; -4 2 4; -5 2 8]
A = 3×3 1 8 -10 -4 2 4 -5 2 8
e = eig(A)
e = 3×1 complex 11.6219 + 0.0000i -0.3110 + 2.6704i -0.3110 - 2.6704i
Since the eigenvalues in
e are the roots of the characteristic polynomial of
poly to determine the characteristic polynomial from the values in
p = poly(e)
p = 1×4 1.0000 -11.0000 0.0000 -84.0000
Characteristic Polynomial of Matrix
poly to calculate the characteristic polynomial of a matrix,
A = [1 2 3; 4 5 6; 7 8 0]
A = 3×3 1 2 3 4 5 6 7 8 0
p = poly(A)
p = 1×4 1.0000 -6.0000 -72.0000 -27.0000
Calculate the roots of
roots. The roots of the characteristic polynomial are the eigenvalues of matrix
r = roots(p)
r = 3×1 12.1229 -5.7345 -0.3884
r — Polynomial roots
Polynomial roots, specified as a vector.
poly([2 -2 3 -3])
Complex Number Support: Yes
A — Input matrix
poly([0 -1; 1 0])
Complex Number Support: Yes
p — Polynomial coefficients
Polynomial coefficients, returned as a row vector.
If the input is a square
pcontains the coefficients for the characteristic polynomial of
If the input is a vector of roots,
pcontains the coefficients for the polynomial whose roots are in
In each case, the
n+1 coefficients in
r = roots(p)and
p = poly(r)are inverse functions of each other, up to roundoff error, ordering, and scaling.
The algorithms employed for
an interesting aspect of the modern approach to eigenvalue computation.
the characteristic polynomial of
the roots of that polynomial, which are the eigenvalues of
which is based on similarity transformations. The classical approach,
which characterizes eigenvalues as roots of the characteristic polynomial,
is actually reversed.
A is an
The algorithm is
z = eig(A); p = zeros(n+1,1); p(1) = 1; for j = 1:n p(2:j+1) = p(2:j+1)-z(j)*p(1:j); end
This recursion is derived by expanding the product,
It is possible to prove that
the coefficients in the characteristic polynomial of a matrix within
roundoff error of
A. This is true even if the eigenvalues
A are badly conditioned. The traditional algorithms
for obtaining the characteristic polynomial do not use the eigenvalues,
and do not have such satisfactory numerical properties.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Code generation does not discard nonfinite input values.
Non-vector inputs produce complex outputs. Vector inputs produce real outputs only when the input is real and either the first or second dimension is fixed at size
See Variable-Sizing Restrictions for Code Generation of Toolbox Functions (MATLAB Coder).
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).