Page 32 - MATLAB an introduction with applications
P. 32
MATLAB Basics ——— 17
1.13 POLYNOMIALS
A polynomial is a function of a single variable that can be expressed in the following form:
…
n
1
f(x) = a x + a x n–1 + a x n–2 + + a n–1 x + a n
2
0
1
where the variable is x and the coefficients of the polynomial are represented by the values a , a , … and so
1
0
on. The degree of a polynomial is equal to the largest value used as an exponent.
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. For example, consider the polynomial
5s + 7s + 2s – 6s + 10
5
2
4
To enter this into MATLAB, we enter this as a vector as
>>x = [5 7 0 2 –6 10]
x =
5 7 0 2 –6 10
It is necessary to enter the coefficients of all the terms.
MATLAB contains functions that perform polynomial multiplication and division, which are listed below:
conv(a, b): Computes a coefficient vector that contains the coefficients of the product of polynomials
represented by the coefficients in a and b. The vectors a and b do not have to be the same size.
[q, r] = deconv(n, d): Returns two vectors. The first vector contains the coefficients of the quotient and the
second vector contains the coefficients of the remainder polynomial.
The MATLAB function for determining the roots of a polynomial is the roots function:
root(a): Determines the roots of the polynomial represented by the coefficient vector a.
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. 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:
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.
The value of a polynomial can be computed using the polyval function, polyval (a, x). It evaluates a polynomial
with coefficients a for the values in x. The result is a matrix the same size as x. For instance, to find the value
of the above polynomial at s = 2,
>>x = polyval([5 7 0 2 –6 10], 2)
x =
278
To find the roots of the above polynomial, we enter the command roots (a) which determines the roots of the
polynomial represented by the coefficient vector a.
>>roots([5 7 0 2 –6 10])
ans =
–1.8652
–0.4641 + 1.0832i
–0.4641 – 1.0832i
0.6967 + 0.5355i
0.6967 – 0.5355i
F:\Final Book\Sanjay\IIIrd Printout\Dt. 10-03-09