Sunteți pe pagina 1din 5

ECE120L INTRODUCTION TO MATLAB

LABORATORY ACTIVITY #3
Polynomials and Partial Fraction Expansion

I. Learning Objectives:
At the end of the laboratory activity, the students should be able to:
1. To describe polynomials in MATLAB
2. To implement polynomials addition, subtraction, scalar multiplication, multiplication, and division with
MATLAB
3. To determine the roots of polynomials
4. To implement partial fraction expansion with MATLAB

II. Primer:
A. Polynomials
MATLAB is capable working with polynomials which are used in many advanced courses and applications
in engineering. To describe a polynomial in MATLAB with a row vector whose elements are the polynomials
coefficients, consider: f ( x) 4 x3 8x 2 7 x 5

>> % to represent the polynomial 4x3-8x2+7x-5


>> clear
>> f = [4, -8, 7, -5]
f=
4 -8 7 -5

Polynomial Algebra
1. Addition and Subtraction
To add and/or subtract two polynomials, add/ subtract the arrays that describe their coefficients. If the
polynomials are of different degrees, add zeros to the coefficient array of the lower degree polynomial.
Consider: f ( x) 10x3 6x 2 2x 10 and g( x) 5x 2 4 x 3 ,

>> % Polynomial addition and subtraction


>> clear
>> f = [10, -6, 2, 10];
>> g = [0, 5, -4, 3];
>> h = f + g %addition
h=
10 -1 -2 13
>> k = f g %subtraction
k=
10 -11 6 7

Thus the result for addition is () = 10 3 2 2 + 13 and for subtraction is


k ( x) 10x 11x 6x 7
3 2

PREPARED BY: RONEL V. VIDAL, PECE 1


2. Scalar Multiplication of Polynomials
To multiply a polynomial by a scalar, simply multiply the coefficient array by that scalar. Consider
() = 10 3 6 2 + 2 + 10 and () = 5 2 4 + 3.

>> % Scalar multiplication of Polynomial


>> clear
>> f = [10, -6, 2, 10];
>> f1 = 5*f %to multiply f(x) by a scalar 5
f1 =
50 -30 10 50
>> g = [0, 5, -4, 3];
>> g1 = 6*g %to multiply g(x) by a scalar 6
g1 =
0 30 -24 18

Thus the result of scalar multiplication is 1 () = 50 3 30 2 + 10 + 50 and 1 () = 30 2 24 + 18.

3. Multiplication and Division of Polynomials


The command conv(a,b) (stands for convolve) computes the product of the two polynomials described
by the coefficient arrays a and b. The two polynomials need not be the same degree. The result is the
coefficient array of the product polynomial.
To perform synthetic division of polynomials, use the command [quotient; remainder] = deconv(num,
den) which computes the results of dividing a numerator polynomial, whose coefficient array is num, by a
denominator polynomial represented by the coefficient array den. The quotient polynomial is given by the
coefficient array quotient, remainder is the remainder polynomial.
Consider () = 20 3 7 2 + 5 + 10 and () = 4 2 + 12 3.

>> %Multiplication of two Polynomials


>> clear
>> f = [20, -7, 5, 10];
>> g = [4, 12, -3];
>> product = conv(f,g)
product =
80 212 -124 121 105 -30

Thus the result is product = 80 5 + 212 4 124 3 + 121 2 + 105 30.

>> %Division of two Polynomials


>> clear
>> f = [20, -7, 5, 10];
>> g = [4, 12, -3];
>> [quotient, remainder] = deconv(f,g)
quotient =
5.0000 -16.7500
remainder =
0 0 221.0000 -40.2500

PREPARED BY: RONEL V. VIDAL, PECE 2


Thus the result is = 5 16.75 and with = 221 40.25.

4. Polynomial Roots
The command roots(a) computes an array containing the roots of a polynomial specified by the
coefficient array a. The result is a column array that contains the polynomials roots. Consider
() = 3 7 2 + 40 34.

>> %Polynomial Roots or >> %Polynomial Roots


>> clear >> clear
>> f =[1, -7, 40, -34]; >> roots([1, -7, 40, -34])
>> roots(f) ans =
ans = 3.0000 + 5.0000i
3.0000 + 5.0000i 3.0000 - 5.0000i
3.0000 - 5.0000i 1.0000
1.0000

The roots are = 1, 3 + 5, 3 5

5. Polynomials Coefficient from Roots


The poly(r) function computes coefficients of the polynomial whose roots are specified by the array r.
The result is a row array that contains the polynomials coefficients.
Given the roots 1, 3 + 5i, and 3 5i, find the polynomial coefficients.

>> %To find polynomial coefficients from the given roots


>> clear
>> r = [1, 3+5i, 3-5i];
>> poly(r)
ans =
1 -7 40 -34

Thus the polynomial is () = 3 7 2 + 40 34.

6. The polyval(a,x) function evaluates a polynomial at specified values of its independent variable x,
which can be a matrix or a vector. The polynomials coefficient array is a
Consider f ( x) 9 x3 5x 2 3x 7 . To evaluate at the points x = 0, 2, 4, 6, 8, 10, type

>> %Evaluates a polynomial at specified values of x


>> clear
>> a = [9 -5 3 7];
>> x = [0:2:10];
>> f = polyval(a,x)
f=
7 65 515 1789 4319 8537

PREPARED BY: RONEL V. VIDAL, PECE 3


B. Partial Fraction Expansion with MATLAB

Consider:
B( s) Num b0 s n b1 s n 1 ...... bn
n
A( s ) Den s a1 s n 1 ...... a n

Num = [b0, b1, . bn] coefficient of the numerator


Den = [1, a1, a2, an] coefficient of the denominator

The command [r,p,k] = residue(Num,Den) finds the residue (r), poles (p), and direct terms (k) of a
partial fraction expansion.
B( s ) r (1) r ( 2) r(n)
........ k ( s)
A( s ) s p(1) s p( 2) s p( n )

Example:
Consider:
B( s ) 2 s 3 5s 2 3s 6

A( s ) s 3 6s 2 11s 6
The MATLAB program:

>> %partial - fraction expansion of polynomials(Num & Den)


>> Num = [2 5 3 6]; %coefficient of the numerator
>> Den = [1 6 11 6]; %coefficient of the denominator
>> [r,p,k] = residue(Num,Den)
r=
-6.0000
-4.0000
3.0000
p=
-3.0000
-2.0000
-1.0000
k=
2

Partial fraction expansion of B(s)/A(s):

B( s ) 6 4 3
2
A( s) s 3 s 2 s 1

PREPARED BY: RONEL V. VIDAL, PECE 4


III. Laboratory Excercises

A. Polynomials
() = 4 3 3 6 5
() = 3 + 2 2 + 4

() = 4 4 3 3 7 2 + 2 + 4
() = 2 3 + 3 2 2 + 5

1. Add, subtract, multiply, and divide each pair of polynomials


2. Multiply the four polynomials by 4, 5, 6, and 7, in that order
3. Find the roots of each four given polynomials
4. Use the results of part 3 to find the polynomial coefficients from the given roots
5. Evaluate the four polynomials at the point x =1, 3, 5, and 2

B. Partial Fraction Expansion with MATLAB


Determine the partial fraction expansion of the following:
10( + 7)
() =
( + 3)( + 6)
5 + 2 4 + 4 3 + 2 + 3
() = 6
+ 7 5 + 3 4 + 2 3 + 2 + 3
4 + 2 3 + 5 2 + + 1
() = 5
+ 3 4 + 2 3 + 4 2 + 5 + 2
3 + 4 2 + 6 + 5
() =
( + 8)( 2 + 8 + 3)( 2 + 5 + 7)

PREPARED BY: RONEL V. VIDAL, PECE 5

S-ar putea să vă placă și