Week 1
Week 1
Week 1
Dr. Nalesh S
Assistant Professor
The Exercises are meant for Control System Lab (20-305-0206) for MSc 2nd Semester
at DOE, CUSAT
Experiment1: Familiarizing with Matlab (Week1)
Exercise 1:
Use Matlab command to obtain the following
a) Extract the fourth row of the matrix generated by magic(6)
b) Show the results of ‘x’ multiply by ‘y’ and ‘y’ divides by ‘x’.
Given x = [0:0.1:1.1] and y = [10:21]
c) Generate random matrix ‘r’ of size 4 by 5 with numbers varying between -8 and 9. Multiply this
matrix with a 5 by 5 magic square matrix. Print the 3rd row of the result.
Exercise2:
Use MATLAB commands to get exactly as the figure shown below
x=pi/2:pi/10:2*pi; y=sin(x); z=cos(x);
Experiment2: Polynomials in Matlab (Week1)
Representing Polynomials
MATLAB represents polynomials as row vectors containing coefficients ordered by descending
powers. For example, consider the equation
This is the celebrated example Wallis used when he first represented Newton's method to the French
Academy. To enter this polynomial into MATLAB, use
>>p = [1 0 -2 -5];
Polynomial Roots
The roots function calculates the roots of a polynomial:
>>r = roots(p)
r=
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
By convention, MATLAB stores roots in column vectors. The function poly returns to the polynomial
coefficients:
>>p2 = poly(r)
p2 = 1 8.8818e-16 -2 -5
Polynomial Evaluation
The polyval function evaluates a polynomial at a specified value. To evaluate p at s = 5, use
>>polyval(p,5)
ans = 110
It is also possible to evaluate a polynomial in a matrix sense. In this case the equation
becomes , 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:
>>X = [2 4 5; -1 0 3; 7 1 5];
>>Y = polyvalm(p,X)
Y=
377 179 439
111 81 136
490 253 639
Convolution and Deconvolution
Polynomial multiplication and division correspond to the operations convolution and deconvolution.
The functions conv and deconv implement these operations. Consider the polynomials
and . To compute their product,
>>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:
>>[q,r] = deconv(c,a)
q=4 5 6
r=00000
Polynomial Derivatives
The polyder function computes the derivative of any polynomial. To obtain the derivative of the
polynomial
>>p= [1 0 -2 -5]
>>q = polyder(p)
q = 3 0 -2
polyder also computes the derivative of the product or quotient of two polynomials. For example,
create two polynomials a and b:
>>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.
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
>>b = [-4 8];
>>a = [1 6 8];
>>[r,p,k] = residue(b,a)
r = -12
8
p = -4
-2
k = []
Given three input arguments (r, p, and k), residue converts back to polynomial form:
>>[b2,a2] = residue(r,p,k)
b2 = -4 8
a2 = 1 6 8
Exercise 1:
Consider two polynomials p(s) = s2 + 4s + 4 and q(s) = s2 + 1. Using matlab compute
a. Product of p(s) and q(s)
b. Roots of p(s), q(s) and p(s)*q(s)
c. p(-2), p(0), q(3), q(-1).
Evaluate using pen and paper and compare the results.
Exercise 2:
Use Matlab to find the partial fraction equivalent of the following.
𝑨(𝒔) 𝒔+𝟑
a. 𝑩(𝒔) = 𝒔𝟑+𝟕𝒔𝟐+𝟏𝟎𝒔
𝑨(𝒔) 𝒔𝟐 +𝟓𝒔+𝟔
b. 𝑩(𝒔)
= (𝒔+𝟐)𝟑
𝑨(𝒔) 𝟒𝒔𝟐 +𝟐𝒔+𝟑
c. 𝑩(𝒔)
= 𝒔𝟑 +𝟐𝒔𝟐 +𝒔−𝟏𝟖