0% found this document useful (0 votes)
27 views6 pages

Lab 02 Updated

Uploaded by

ammaradil817
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Lab 02 Updated

Uploaded by

ammaradil817
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Control Systems LAB # 02

Introduction
Matlab is an interactive program for numerical computation and data visualization; it
is used extensively by control engineers for analysis and design. There are many
different toolboxes available which extend the basic functions of Matlab into different
application areas; in these tutorials, we will make extensive use of the Control
Systems Toolbox. Matlab is supported on Unix, Macintosh, and Windows
environments.

MATLAB, its Toolboxes and SIMULINK have become, over several years, the
industry standard software package for control system design. The purpose of this
LAB is to introduce the students to some of the more useful aspects of MATLAB, and
to illustrate how the software may be used to solve problem in control system design.

Vectors
Let's start off by creating something simple, like a vector. Enter each element of the
vector (separated by a space) between brackets and set it equal to a variable. For
example, to create the vector a, enter the Matlab command window (you can "copy"
and "paste" from your browser into Matlab to make it easy):

a = [1 2 3 4 5 6 9 8 7]
Matlab should return:
a =
1 2 3 4 5 6 9 8 7
Let's say you want to create a vector with elements between 0 and 20 evenly spaced in
increments of 2 (this method is frequently used to create a time vector):
t = 0:2:20

t =
0 2 4 6 8 10 12 14 16 18 20
Manipulating vectors is almost as easy as creating them. First, suppose you would like
to add 2 to each of the elements in vector 'a'. The equation for that looks like:
b = a + 2

b =
3 4 5 6 7 8 11 10 9
Now suppose, you would like to add two vectors together. If the two vectors are the
same length, it is easy. Simply add the two as shown below:
c = a + b

c =
4 6 8 10 12 14 20 18 16
Subtraction of vectors of the same length works exactly the same way.
Functions
To make life easier, Matlab includes many standard functions. Each function is a
block of code that accomplishes a specific task. Matlab contains all the standard
functions such as sin, cos, log, exp, sqrt, as well as many others. Commonly used
constants such as pi, and i or j for the square root of -1, are also incorporated into
Matlab.

sin(pi/4)

ans =

0.7071

To determine the usage of any function, type help [function name] at the Matlab
command window.

Matlab even allows you to write your own functions with the function command;
follow the link to learn how to write your own functions and see a listing of the
functions we created for this tutorial.

Polynomials
In Matlab, a polynomial is represented by a vector. To create a polynomial in Matlab,
simply enter each coefficient of the polynomial into the vector in descending order.
For instance, let's say you have the following polynomial:

To enter this into Matlab, just enter it as a vector in the following manner.
x = [1 3 -15 -2 9]

x =
1 3 -15 -2 9
Matlab can interpret a vector of length n+1 as an nth order polynomial. Thus, if your
polynomial is missing any coefficients, you must enter zeros in the appropriate place
in the vector. For example,

would be represented in Matlab as:

y = [1 0 0 0 1]
You can find the value of a polynomial using the polyval function. For example, to
find the value of the above polynomial at s=2,
z = polyval([1 0 0 0 1],2)

z =
17

You can also extract the roots of a polynomial. This is useful when you have a high-
order polynomial such as
Finding the roots would be as easy as entering the following command;

roots([1 3 -15 -2 9])

ans =
-5.5745
2.5836
-0.7951
0.7860

Let's say you want to multiply two polynomials together. The product of two
polynomials is found by taking the convolution of their coefficients. Matlab's function
conv that will do this for you.

x = [1 2];
y = [1 4 8];
z = conv(x,y)

z =
1 6 16 16
Dividing two polynomials is just as easy. The deconv function will return the
remainder as well as the result. Let's divide z by y and see if we get x.
[xx, R] = deconv(z,y)

xx =
1 2

R =
0 0 0 0

Time Domain Analysis


This part introduces the reader to time domain analysis using MATLAB. It uses
commands from the Control System Toolbox. A list of the commands can be found
using

>> help control

More information on individual commands can be obtained, for example

>> help step

will provide more detail on how to use the step command.

1
Example 1: Consider a first-order transfer function G( s) = . The impulse
s +1
response function can be created by using following commands in script file.
% impulse response
% num and den contains polynomial coefficients
% in descending powers of s
clf
num = [1];
den = [1 1];
impulse (num,den);
grid;
printsys(num,den,’s’);

Ramp response using SIMULINK


The Control System Toolbox does not process a ‘ramp’ command, but the ramp
response can be obtained using SIMULINK, which is an easy to use Graphical User
Interface (GUI). SIMULINK allows a block diagram representation of a control
system to be constructed and real-time simulation performed.

Figure 1: Ramp response of first order system

Q1: Use MATLAB commands to find ramp response of the First order system given
in figure 1 and compare results.
Example 2: For the circuit of Figure 2, the initial conditions are i L (0 − ) = 0 , and
vc (0 − ) = 0.5V . We will compute vc (t ).

Figure 2: Circuit for Example 2


dvC
For this example, i = i L = iC = C (1)
dt
diL
and by Kirchoff’s voltage law (KVL), RiL + L + vC = uo (t ) (2)
dt
After substituting numerical values of constants and solving we get
d 2 vC dv
2
+ 4 C + 3vC = 3 t >0 (3)
dt dt
Solving second order differential equation (3) we get
vC (t ) = (−0.75e −t + 0.25e −3t + 1)u o (t ) (4)
Solving using SIMULINK

Figure 3: Block Diagram of Example 2

Figure 4: SIMULINK Implementation of Example 2

Problems:

Transfer functions:

5 5 s+2
G1 (s) = G2 (s) = G3 ( s) = ,
s +1 s −1 s +1
s−2 s−2
G4 ( s ) = G5 ( s) =
s +1 s −1
Observe the step response of the above five transfer function and draw conclusions.

SIMULINK Implementation:

d4y d3y d2y dy


a) 4
+ a 3 + a 2 2
+ a1 + ao y (t ) = u (t )
dt dt dt dt
a3 = 0 , a2 = 2 , a1 = 0 , ao = 1 and u (t ) = sin t

d4y d3y d2y dy


b) 4
+ a 3 + a 2 2
+ a1 + ao y (t ) = u (t )
dt dt dt dt
a3 = 3 , a2 = 2 , a1 = −2 , ao = 1 and u (t ) = sin t

Implement both differential equation (a) and (b) using SIMULINK and script file.

You might also like