0% found this document useful (0 votes)
9 views

Chapter 2

This document discusses polynomials in MATLAB. It defines a polynomial as a function of a single variable that can be expressed as a sum of terms with coefficients multiplied by variables raised to exponents. In MATLAB, polynomials are represented by vectors with coefficients in descending order. Functions like conv(), deconv(), roots(), poly(), polyder(), and polyint() allow performing operations like multiplication, division, finding roots, derivatives, integrals and evaluating polynomials. Examples are provided for each function. Exercises at the end involve writing programs to find tangent lines, extrema, areas under and between polynomials.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chapter 2

This document discusses polynomials in MATLAB. It defines a polynomial as a function of a single variable that can be expressed as a sum of terms with coefficients multiplied by variables raised to exponents. In MATLAB, polynomials are represented by vectors with coefficients in descending order. Functions like conv(), deconv(), roots(), poly(), polyder(), and polyint() allow performing operations like multiplication, division, finding roots, derivatives, integrals and evaluating polynomials. Examples are provided for each function. Exercises at the end involve writing programs to find tangent lines, extrema, areas under and between polynomials.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Chapter 2

Polynomials

A polynomial is a function of a single variable that can be expressed in the


following form:
f (x)=a0 x n+ a1 x n−1 +a 2 x n−2+ …+a n – 1 x 1+ an

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.

2.1 Input Polynomial


A vector represents a polynomial in MATLAB. When entering the data in
MATLAB, simply enter each coefficient of the polynomial into the vector in
descending order.

Example 2.1:- consider the polynomial p ( s )=5 s5 +7 s4 + 2 s2 – 6 s+ 10

To enter this into MATLAB, we enter this as a vector as

>> 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.

2.2 Polynomial multiplication and division


MATLAB contains functions that perform polynomial multiplication and division,
which are listed below:

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.

Example 2.2:- consider the polynomials


4 2
p ( x )=x −4 x + 2 x +1 and q ( x )=x +2
then to find h ( x )= p ( x )∗q ( x ) write Matlab code as follows

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.

Example 2.3: - consider the polynomials


p ( x )=x −4 x + 2 x +1 and q ( x )=x +2
4 2 2

then to find h ( x )= p ( x ) /q ( x ) write Matlab code as follows

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

2.3 Polynomial Algebraic

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

are four real roots of polynomial p.

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

2.4 Polynomial Calculus

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.

You might also like