Sunteți pe pagina 1din 3

MECH3430 Measurement and Control

Computer Labs
Dr. Nariman Sepehri

As part of the requirements for the course, students must complete a set of three computer assignments
using MATLAB software. The purpose of the assignments is to familiarize students with the MATLAB
environment by solving a series of control related problems during the tutorial. Topics of interest will
include time response simulations of a dynamic system, both open and closed-loop. Students will also
learn how to generate root locus, Bode, and polar plots, which are all useful tools for control system
design and analysis. Each assignment will build on the previous one such that, as a whole, the set of
three computer assignments will expose students to most of the common tools utilized by control
engineers at various stages of the control system development process.

***********************************************************************************
MECH3430 Measurement and Control
Computer Lab#1 (C1)

The MATLAB Environment


MATLAB is a matrix-based software package designed for mathematical and engineering
computations. MATLAB is generally used in command-line mode. When single commands are entered
on the command-line, MATLAB processes them immediately and displays the results. Although it is
possible to complete all of the requirements for this assignment using the command-line, we will use
the MATLAB editor to create a simple script that executes the necessary commands. The advantages of
using the MATLAB editor include the ability to debug your code without having to retype all the
commands on the command-line and the ability to save your work for later use.
Besides completing the assignments for the course, students are encouraged to explore MATLAB on
their own. Useful resources for those wishing to learn more about the MATLAB package are:

1. The Mathworks website, which has all of the MATLAB documentation available in both html
and Adobe PDF format. The URL is:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml
2. Appendix B of your course textbook.
3. Information about particular functions can be accessed directly from the command-line by
typing help name_of_function. For example, help plot prints information related to the
plot function directly to the command window.
4. MATLAB also has an integrated help system, similar to that available on the Mathworks
website. The help system can be accessed by typing helpdesk on the command-line. The
integrated help system may occasionally function strangely over the campus network.
Therefore, it is suggested the students consult the Mathworks website instead.

Exercises
In this assignment you will create a MATLAB script and use it to run an open-loop time simulation of
1
a dynamic system having transfer function, G ( s ) = . In subsequent assignments, the closed-loop
( s + 1) 2
response of this same system will be investigated. Graphical design tools such as the root locus and the
Bode plot will also be examined later in the course using this dynamic system as a model plant.
To begin the assignment, locate and launch MATLAB software to open the MATLAB command
window. Next, type the word edit (omitting the quotes of course) on the command-line (the rightmost
pane of the MATLAB window) and press Enter to open the MATLAB editor. Here, you will write the
script to complete the assignment. All of the output, however, will be directed to the command window
by default.
Type the following script into the MATLAB editor (Note that you may wish to skip the comments to
save time):

%25.343 MATLAB Assignment #1


%
%NAME:
%STUDENT #:
%DATE:
%define a Laplace variable 's'. This allows you to type in the transfer %function using the familiar s
notation.
s=zpk('s');
G=1/(s+1)^2
%set up a simulation
step(G); %this give the time response to a step input but lacks
%alternative and more useful method to simulate a time response
%time=0:0.01:1; %Create a vector of times at which to evaluate y(t). %Command
time=0:0.01:1; means start at 0 sec and %increase the time by 0.01
sec until the time is 1 sec.
%u(1:length(time))=1.0; %Create an input vector, i.e. u(t). Setting all the %elements of u to 1.0
generates a unit step input.
%y=lsim(G,u,time); %Command y=lsim(G,u,time); simulates the response of %G(s) to
input vector u.
%plot(time,u,'--'); %Plot the input signal as a dashed line.
%hold on %Create the next plot on the current axes.
%plot(time,y); %Plot the step response on the same figure as the input %signal.
%hold off
Run the script by selecting Run from the Debug menu or by pressing function key F5 on the keyboard.
If you havent made any mistakes in copying the script, the following output should have appeared in
the MATLAB command window:

Zero/pole/gain:
1
---------
(s+1)^2

A plot of the step response of G(s) should also have been generated by the command step(G). Two
things with respect to the script editor are worth noting at this point. First, the use of % turns off a
line of code by commenting out whatever text follows. The second note is on the use of a semicolon ;
at the end of a line. The semicolon is used to suppress printing of intermediate results to the command
line. In other words, the command is executed but the results are not displayed. For example, clear the
MATLAB command window by typing clc at the command-line. Next, try typing a semicolon
immediately following the line G=1/(s+1)^2 in the script and run the script again. No output should
be printed to the command window. Use of the semicolon helps control display of computed results
and allows you to print only the results you need to see to the command window.
After you have familiarized yourself with the script complete the following exercises.
1. Modify the MATLAB script to plot the time response of transfer function G(s) to a step input
of magnitude 2.3 for a period of 15 seconds using command lsim. To do this comment
out the command step(G) and turn on the remainder of the script, being careful not to
turn on the comments as this will generate errors at run time. Modify the script where
necessary to set the magnitude of the step input to 2.3 and run the simulation for 15
seconds. Run the script to generate a plot of the response.
2. Annotate the plot with your name and student number, label the plot axes and print the result.
To annotate the plot, click the icon shown below. This will open the annotation tools
dialog. Next select text box and create a text box on the figure. Enter your name and
student number. To label the plot axes, click on the tool bar and then click anywhere
on the plot. You may now enter the axis labels directly in the bottom dialog box.

click to show
annotation tools
3. Confirm that the steady-state value of the time response indicated by the simulation results
agrees with the theoretical value predicted by the final value theorem.
4. Alternatively, you can use Simulink toolbox to study the behavior of this second order
system. The TA will describe this toolbox during the laboratory session. Repeat steps 1
and 2, and compare the results. You must also present to and, run your program for the
TA at this point. save a copy of your MATLAB script and Simulink file for use in
subsequent MATLAB Assignments.
5. Hand in the following materials, by the end of this lab:

a1. A hardcopy of your complete MATLAB script, with the following header:
%25.343 MATLAB Assignment #1
%Name: ____________
%Student No.: ______________
%Date: _________________

Note: Make sure that all commands you have used to complete the assignment
are included in the script. In other words, if the marker types your script into the
MATLAB editor verbatim, it should generate the same results that you hand in
as hardcopies. If different commands are utilized to complete different parts of
the assignment, they may be commented out as necessary. However, they must
appear correctly in your script.

a2. A hardcopy of your Simulink block diagram.

b. One annotated time response plot as per above exercise for each set of tests.
c. Answer to question 3 above. This may be attached on a separate piece of paper, or
typed or hand-written at the bottom of your MATLAB script.

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