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

Controls - Matlab - E6 - Polynomials in Matlab Eric

This document discusses representing and manipulating polynomials in MATLAB. It provides an overview of MATLAB functions for polynomial operations like roots, evaluation, differentiation, curve fitting, and partial fraction expansion. It then demonstrates various polynomial calculations in MATLAB, such as representing polynomials with coefficients, finding roots, evaluating polynomials, multiplying and dividing polynomials, taking derivatives, and using partial fraction decomposition. Exercises at the end provide additional examples of using MATLAB for polynomial calculations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Controls - Matlab - E6 - Polynomials in Matlab Eric

This document discusses representing and manipulating polynomials in MATLAB. It provides an overview of MATLAB functions for polynomial operations like roots, evaluation, differentiation, curve fitting, and partial fraction expansion. It then demonstrates various polynomial calculations in MATLAB, such as representing polynomials with coefficients, finding roots, evaluating polynomials, multiplying and dividing polynomials, taking derivatives, and using partial fraction decomposition. Exercises at the end provide additional examples of using MATLAB for polynomial calculations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Exercise No.

6
POLYNOMIALS IN MATLAB

NAME: Eric John A. Hornales DATE PERFORMED: July 20, 2018


SECTION: BSEE IV DATE SUBMITTED:
GROUP NO. : INSTRUCTOR: Engr. Catipon

I. Objective:
to learn how to represent polynomials in MATLAB, find roots of polynomials, create polynomials when roots are known and obtain
partial fractions.

II. Overview:

MATLAB provides functions for standard polynomial operations, such as polynomial roots, evaluation, and differentiation. In
addition, there are functions for more advanced applications, such as curve fitting and partial fraction expansion.

Polynomial Function Summary


Function Description
Conv Multiply polynomials
Deconv Divide polynomials
Poly Polynomial with specified roots
Polyder Polynomial derivative
Polyfit Polynomial curve fitting
Polyval Polynomial evaluation
Polyvalm Matrix polynomial evaluation
Residue Partial-fraction expansion (residues)
Roots Find polynomial roots

Symbolic Math Toolbox contains additional specialized support for polynomial operations.

III. Implementation:

1. MATLAB represents polynomials as row vectors containing coefficients ordered by descending powers.
For example, consider the equation

p(x) = x3 – 2x – 5

To enter this polynomial into MATLAB,


type:

p = [1 0 -2 -5];

2. The roots function calculates the roots of a polynomial.


Type:

r = roots(p)

r=
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i

Note: By convention, MATLAB stores roots in column vectors.

3. The function poly returns to the polynomial coefficients:

p2 = poly(r)

p2 =
1 8.8818e-16 -2 -5

poly and roots are inverse functions,

For LPU Cavite use only Exercise 5 – Polynomials in Matlab


Evaluation copy
Student’s Manual Page 1 of 4
4. The poly function also computes the coefficients of the characteristic polynomial of a matrix:
Type:

A = [1.2 3 -0.9; 5 1.75 6; 9 0 1];


poly(A)

ans =
1.0000 -3.9500 -1.8500 -163.2750

Note: The roots of this polynomial, computed with roots, are the characteristic roots, or eigenvalues, of
the matrix A. (Use eig to compute the eigenvalues of a matrix directly.)

5. The polyval function evaluates a polynomial at a specified value. To evaluate p at s = 5, use


Type:
polyval(p,5)

ans =
110

6. It is also possible to evaluate a polynomial in a matrix sense.


In this case the equation

p(x) = x3 – 2x – 5

becomes p(X) = X3 – 2X – 5I, where X is a square matrix and I is the identity matrix.

For example, create a square matrix X and evaluate the polynomial p at X:

Type:
X = [2 4 5; -1 0 3; 7 1 5];
Y = polyvalm(p,X)

Y=
377 179 439
111 81 136
490 253 639

7. Polynomial multiplication and division correspond to the operations convolution and deconvolution. The functions conv and
deconv implement these operations.

Consider the polynomials a(s) = s2 + 2s + 3 and b(s) = 4s2 + 5s + 6. To compute their product,
Type:

a = [1 2 3]; b = [4 5 6];
c = conv(a,b)

c=
4 13 28 27 18

Use deconvolution to divide back out of the product.


Type:

[q,r] = deconv(c,a)

q=
456
r=
00000

8. The polyder function computes the derivative of any polynomial. To obtain the derivative of the polynomial
Type:

p= [1 0 -2 -5]
q = polyder(p)

q=
3 0 -2

For LPU Cavite use only Exercise 5 – Polynomials in Matlab


Evaluation copy
Student’s Manual Page 2 of 4
9. Polyder also computes the derivative of the product or quotient of two polynomials.

For example, create two polynomials a and b, type:

a = [1 3 5];
b = [2 4 6];

Calculate the derivative of the product a*b by calling polyder with a single output argument:

c = polyder(a,b)

c=
8 30 56 38

Calculate the derivative of the quotient a/b by calling polyder with two output arguments:

[q,d] = polyder(a,b)

q=
-2 -8 -2

d=
4 16 40 48 36

q/d is the result of the operation.

10. ‘residue’ finds the partial fraction expansion of the ratio of two polynomials. This is particularly useful for applications that
represent systems in transfer function form.

For polynomials b and a,

if there are no multiple roots, where r is a column vector of residues, p is a column vector of pole locations, and k is a row vector of
direct terms.

Consider the transfer function

Type:

b = [-4 8];
a = [1 6 8];
[r,p,k] = residue(b,a)

r=
-12
8

p=
-4
-2

k=
[]

11. Given three input arguments (r, p, and k), residue converts back to polynomial form:
Type:
[b2,a2] = residue(r,p,k)

b2 =
-4 8

a2 =
168

For LPU Cavite use only Exercise 5 – Polynomials in Matlab


Evaluation copy
Student’s Manual Page 3 of 4
IV. Exercises:

1. Consider the two polynomials p(s) = s2 + 2s + 1 and and q(s) = s + 1. Using MATLAB, compute:

a. p(s)*q(s) = s2 +3s2 3s + 1

Matlab code:

clear;clc
format short
p=[1 2 1]; q=[1 1];
z=conv(p,q)

b. Roots of p(s) and q(s) = x = -1 , x = -1 ; y = -1

Matlab code:

clear;clc
format short
p=[1 2 1]; q=[1 1];
x=roots(p)
y=roots(q)

c. p(-1) and q(6) = x=0 ; y=7

Matlab code:

clear;clc
format short
p=[1 2 1]; q=[1 1];
x=polyval(p,-1)
y=polyval(q,6)

2. Use MATLAB command to find the partial fraction of the following:

Answers:
a) B(s) / A(s) = ((-6) / (s + 3)) + ((-4) / (s + 2)) + 2

Matlab code:

clear;clc
format short
B=[2 5 3 6]; A=[1 6 11 6];
[r,p,k] = residue(B,A)

b) B(s) / A(s) = ((1) / (s+1)) + ((2) / (s + 1))

Matlab code:

clear;clc
format short
B=[1 2 3]; A=[1 3 3 1];
[r,p,k] = residue(B,A)

V. Generalization:
After executing this activity, I have come to generalize how to represent polynomials in MATLAB, find roots of polynomials, create
polynomials when roots are known and obtain partial fractions.

For LPU Cavite use only Exercise 5 – Polynomials in Matlab


Evaluation copy
Student’s Manual Page 4 of 4

You might also like