Controls - Matlab - E6 - Polynomials in Matlab Eric
Controls - Matlab - E6 - Polynomials in Matlab Eric
6
POLYNOMIALS IN MATLAB
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.
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
p = [1 0 -2 -5];
r = roots(p)
r=
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
p2 = poly(r)
p2 =
1 8.8818e-16 -2 -5
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.)
ans =
110
p(x) = x3 – 2x – 5
becomes p(X) = X3 – 2X – 5I, where X is a square matrix and I is the identity matrix.
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
[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
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
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.
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.
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
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)
Matlab code:
clear;clc
format short
p=[1 2 1]; q=[1 1];
x=roots(p)
y=roots(q)
Matlab code:
clear;clc
format short
p=[1 2 1]; q=[1 1];
x=polyval(p,-1)
y=polyval(q,6)
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)
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.