You are on page 1of 4

SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT

LAB#4:
POLYNOMIALS IN MATLAB

The learning objectives are:

 Writing a polynomial in MATLAB


 Perform different operations on polynomials
 Generate a polynomial from given roots
 Obtain a characteristics polynomial for a given Matrix
 Compute the derivative and integration of a polynomial
 Fit a polynomial curve for a given set of point
 Evaluate polynomial with matrix argument

Introduction:
A polynomial is an expression in which a finite number of constants and variables are
combined using addition subtraction multiplication and non-negative whole number
exponents (raise to power). Thus the following expressions are all considered polynomials.
2
 x + 2 x−7
4 3
 x −7 x
 x
The MATLAB software provides built-in functions for standard operation on polynomials such
as arithmetic operation like multiplication and division etc., evaluation of roots,
differentiation, and integration and so on. In addition there are functions for more advance
applications such as curve fitting. Polynomials have a very significant role to play in
engineering system analysis. The polynomial functions are stored in a polyfun directory in
MATLAB.

Entering a Polynomial:
In MATLAB, a polynomial is represented by a row vector. Polynomials are entered with
variable term arranged in descending order of its power. Only the coefficient of variable terms
are entered i.e. variables are not entered. The left most term is the highest power term of the
variable and the right most term is the constant term with variables raise to the power zero.
The total number of term is always one more than the order of the polynomial. The coefficient
of polynomial is entered as an element of a row vector and can be separated from each other
by blank space or comma. For example:

p ( x ) =x 4 +3 x3 −15 x 2−2 x +9

This can entered in MATLAB as a row vector ‘P’ as column.

p=[1 3 −15−2 9] or p=[1,3 ,−15 ,−2,9 ]

MATLAB MANUAL 1
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT

MATLAB can interrupt a vector of length (n+1) as an nth order polynomial. Thus, if there are
missing terms, zeroes must be entered in the appropriate places in the vector.

e.g. y=x 3 +1

In MATLAB: y=[10 0 1] or y=[1,0,0,1]

Two zeroes have been included in a vector to account for missing powers of x, i.e. x 2 and x .

Arithmetic Operations on Polynomials:

Operations Syntax Description


X and y are two vectors for two
Addition of two polynomials and z vector is their resultant.
Z=x+ y
polynomials The dimension (size) of both polynomials
vectors must be same for addition.

For subtraction also, the size/dimensions


of both vectors must be same. If the
Subtraction of Two
Z=x− y number of terms of two polynomials is not
Polynomials
equal, then zero is padded as coefficient to
make dimensions of vector same.

X and y are the vectors of coefficients of


polynomials to be multiplied and z
contains the coefficient of the resultant
Multiplication of Two conv ( x , y) polynomials.
Polynomials Or z=conv( x , y) If there are more than two polynomials,
then the product is obtained by
performing multiplication of two of the
polynomials at one time.

Z = Dividend vector,
Division of Two y = Divisor vector,
[ x , r ]=deconv (z , y )
Polynomials x = Vector of quotients obtained,
r = vectors of remainders obtained.

Useful Commands for Polynomials:

List Of Commands Description


polyval( p , x) Evaluate polynomials at ‘x’
roots ( p) Computes the roots of polynomial
conv ( p , q) Multiplication of two polynomials
deconv ( p , q) Division of two polynomials
poly(r ) Converts given roots to polynomial

MATLAB MANUAL 2
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT

polyder( p) Differentiate a polynomial


Integrates polynomial analytically, ‘c’ is constant
polyint ( p , c ) of integration. If it is not mentioned in command,
1 is taken by default at place of ‘c’.
polyfit ( x , y , k ) Fits a polynomial to given data

ILLUSTRATIVE PROGRAMS:
Task#1:
Obtain the Values of the following Polynomials at x=-2, 4, 5 and 2+3i?
 P(x) = x2 +4x +1.
 P(x) = x2 + 1
 P(x) = x2 +4x + 2.

Task#2:
Find the Roots of the following Polynomials?
 P1 = x2 + 3x +2.
 P2 = x4 + 4x3 + 9x +2.
 P3 = x5 + 1.
 P4 = x3 + 3x2 + 4x + 1.

Task#3:
Multiply the following Polynomials?
 P1 = x + 3.
 P2 = x + 6.
 P3 = x2 + 4x +6.

Task#4:
Divide Polynomial P by q?
a) P = x3 + 4x +10. Q = x3 + 3x2 + 4x + 2.
b) P = 5x2 + 8x + 2. Q = x2 + x + 2.
c) P = 2x2 + 3x + 1. Q =x2 + x – 1.

Task#5:
Roots of Polynomial are given below find the Corresponding Polynomials?
a) r1 = 2, 4.
b) r2 = -2, -4.

MATLAB MANUAL 3
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT

c) r3 = -2, 4.
d) r4 = -2, 4, 6.

Task#6:
Find Polynomial of Degree 5 for a given Data, for x=12?

X: 2 5 7 9 11 13
Y: 24 156 384 580 650 780

Task#7:
Evaluate the Derivative and Integral of the following Polynomials?
 P1 = x4 + 4x3 + 10x2 + 20x + 15, c = 1.
 P2 = x3 + x + 10, c = 3.
 P3 = x + 5, c = -3.

Task#8:
Express the following system of linear equations into Matrix form and obtain the solution of
the variables x, y, z.
x + y−z=2
−x +3 y−z=2
3 x+ 5 y −2 z =2

MATLAB MANUAL 4

You might also like