Chapter 2
Chapter 2
Polynomials
where the variable is x and the coefficients of the polynomial are represented by
the values a0, a1, … and so on. The degree of a polynomial is equal to the largest
value used as an exponent.
>> p = [5 7 0 2 – 6 10]
p =
5 7 0 2 – 6 10
It is necessary to enter the coefficients of all the terms.
conv(p, q)
Let p ( x ) and q (x) be two polynomial of degree n and m respectively, to find
h ( x )= p ( x )∗q (x) using h=conv(p, q) computes a coefficient vector that contains the
coefficients of the product of polynomials represented by the coefficients in p and
q. The vectors p and q do not have to be the same size.
p=[1 0 -4 2 1];
q=[1 2];
h=conv(p,q)
result is
h =
1 2 -4 -6 5 2
or
5 4 3 2
h ( x )=x +2 x −4 x −6 x +5 x +1
deconv(p, q)
Let p ( x ) and q (x) be two polynomial of degree n and m respectively, to find
h ( x )= p ( x ) /q(x ) using [h, r]=deconv(p, q)
Returns two vectors. The first vector contains the coefficients of the quotient and
the second vector contains the coefficients of the remainder polynomial.
p=[1 0 -4 2 1];
q=[1 0 2];
[h,r]=deconv(p,q)
result is
h =
1 0 -6
r =
0 0 0 2 13
or
h ( x )=x −6 and r ( x )=2 x+13
2
roots(p)
Let p ( x ) is a polynomial the MATLAB function for determining the roots of a
polynomial is the roots function. r=roots(p) determines the roots of the
polynomial represented by the coefficient vector p. The roots function returns a
column vector containing the roots of the polynomial, the number of roots is equal
to the degree of the polynomial.
Example 2.4: - consider the polynomial p ( x )=x 4−4 x 2+ 2 x +1 then to find the roots
of p write Matlab code as follows
p=[1 0 -4 2 1];
r=roots(p)
result is
r =
-2.1701
1.4812
1.0000
-0.3111
poly(r)
When the roots of a polynomial are known, the coefficients of the polynomial are
determined when all the linear terms are multiplied, we can use the poly function
p=poly(r) Determines the coefficients of the polynomial whose roots are contained
in the vector r. The output of the function is a row vector containing the
polynomial coefficients.
Example 2.5: - consider the polynomial r =[12 0−4 ] ,then to find the p(x ) with
roots r, write Matlab code as follows
r=[1 2 0 -4];
p=poly(r)
result is
p =
1 1 -10 8 0
or
4 3 2
p ( x )=x + x −10 x + 8 x
polyval (p, x)
The value of a polynomial can be computed using the polyval function
y=polyval(p, x) it evaluates a polynomial with coefficients p for the values in x.
The result is a matrix the same size of x.
Example 2.6: - consider the polynomial p ( x )=x 4−4 x 2+ 2 x +1 and x=2, then to find
the p(2) write Matlab code as follows
p=[1 0 -4 2 1];
x=2;
y=polyval(p,x)
result is
y =
5
polyder(p)
Let p ( x ) is a polynomial the MATLAB function for determining the derivative of
p(x ) is q=polyder(p) returns the derivative of the polynomial represented by the
coefficients in p,
d
q (x)= p (x).
dx
e
h = polyder(p,q) returns the derivative of the product of the polynomials p and q,
d
h( x)= [ p ( x )∗q(x )].
dx
le
[h,r] = polyder(p,q) returns the derivative of the quotient of the
polynomials p and q,
h(x ) d p(x )
=
r ( x) dx q(x )
Example 2.7: - consider the polynomial p ( x )=x 4−4 x 2+ 2 x +1, then to find the
derivative of p write Matlab code as follows
p=[1 0 -4 2 1];
q=polyder(p)
result is
q =
4 0 -8 2
or
3
q ( x )=4 x −8 x +2
polyint
Let p ( x ) is a polynomial the MATLAB function for determining the integration of
p(x ) is q = polyint(p,k) returns the integral of the polynomial represented by the
coefficients in p using a constant of integration k. q = polyint(p) assumes a
constant of integration k = 0.
Example 2.8: - consider the polynomial p ( x )=4 x 3 −3 x 2 +8 x +1, then to find the
integration of p write Matlab code as follows
p=[4 -3 8 1];
q=polyint(p)
result is
q =
1 -1 4 1 0
or
4 3 2
q ( x )=x −x −4 x + x
Exercises
1- Write a program to find the tangent line of polynomial p(x ) at the point x 0
then draw the graph of polynomial ant its tangent line.
2- Write a program to find all local maximum and minimum pints of
polynomial p(x ) then draw polynomial and (max., min.) points.
3- Write a program to find the area under polynomial p(x ) if its bounded.
4- Write a program to find the area under polynomial p(x ) on interval [a , b].
5- Write a function to add two polynomial p(x ) and q (x).
6- Write a function to subtract two polynomial p(x ) and q (x).
7- Write a program to find the area between two polynomials p(x ) and q (x) if
its bounded.