In Matlab, a polynomial is represented by a row vector of its
coefficients. If the polynomial has degree n, the corresponding representing
vector has length n+1 and contains the coefficients associated with
decreasing powers from left to right. Zero coefficients must be marked as
zero entries. For example, [3 2 1]
represents P(r) = 3r2 + 2r + 1 whereas
[1 0 0]
represents P(r) = r2.

The command polyval(vector,arg)
interprets vector as polynomial and
evaluates it at arg, which can be a number, a vector or
even a matrix (pointwise evaluation - like sin(x) if x is an array).

Example:

» p=[1 2
1];polyval(p,1),polyval(p,[1 2])

ans =

4

ans =

4
9

This allows to plot polynomials in the usual way using plot. For example, with the commands

»
r=linspace(-2,0,100);plot(r,polyval([1 2 1],r))

a plot of P(r) = r2+2r+1 in the range -2 £ r £ 0 is
created using 100 supporting points. 2. Derivatives

Another useful command is
polyder(vector). Here again the vector argument is interpreted as
polynomial and the output is the vector representing the derivative of this
polynomial. For example, the derivative of P(r) = r2+2r+1
(vector [1 2 1]) is P'(r)=2r+2
(vector [2 2]) which you can find by executing

» polyder([1 2 1])

ans =

2
23. Roots

Root command. The most important command is root(vector)which finds numerically all
roots of the polynomial associated with the vector argument. Let's define a
polynomial of degree 6 with random coefficients and compute its roots:

The first output shows 7 random numbers between 0 and 1 to which a
polynomial of degree 6 is associated. The second output contains numerical
approximations of the 6 roots of this poynomial which are stored in a column
vector. Let's confirm that the third number of the last answer is indeed a
root:

» polyval(p,ans(3))

ans =

9.1073e-016
+7.8063e-017i

Multiple roots. There are some complications with multiple roots.
For second degree polynomials these are usually recognized, but not
necessarily for polynomials of higher degree. The polynomials r2+2r+1
and r3+3r2
+3r+1 have just one root r = -1, but