Professional Documents
Culture Documents
Lab Manual
Lab Manual
Lab Manual
Lab. Manual
1
Table of Contents
General Introduction…………………………………………………..………….3
The Purpose of This Manual……………………………………………………..4
Lab Instructions………………………………………………………….……….4
Part One
M-Files & Function Files
Lab. No. 1………………………………………………….………………...…….5
Lab. No. 2………………………………………………………………..……….13
Lab. No. 3…………………………………………………………………..…….14
Lab. No. 4……………………………………………………………………..….19
Lab. No. 5……………………………………………………………….…….….24
Lab. No. 6……………………………………………………………….…….….25
Part Two
Simulink
Introduction……………..……………………………………………………….26
Starting Simulink………………………………………………………..……….27
1st Model………………………………………………………………………….28
Running Simulations…………………………………………………………….30
2nd Model……………………………………………………………………...….31
3rd Model………………………………………………………………………….32
4th Model………………………………………………………………………….33
5th Model………………………………………………………………………….34
2
General Introduction
• MATLAB is a powerful language for technical computing. The name
MATLAB stands for MATrix LABoratory, because its basic data element is
a matrix (array).
• MATLAB can be used for math computations, modeling and simulations,
data analysis and processing, visualization and graphics, and algorithm
development.
• MATLAB is widely used in universities and colleges in introductory and
advanced courses in mathematics, science, and especially in engineering. In
industry the software is used in research, development and design. The
standard MATLAB program has tools (functions) that can be used to solve
common problems.
• In addition, MATLAB has optional toolboxes that are collections of
specialized programs designed to solve specific types of problems.
Examples include toolboxes for signal processing, symbolic calculations,
and control systems.
• Until recently, most of the users of MATLAB have been people who had
previous knowledge of programming languages such as FORTRAN or C,
and switched to MATLAB as the software became popular. Consequently,
the majority of the literature that has been written about MATLAB assumes
that the reader has knowledge of computer programming.
3
The Purpose of This Manual
This manual is intended for students who are using MATLAB for the first time and
have little or no experience in computer programming.
Lab Instructions
When you attend to the lab you must follow the following instructions:
2. Try to use the same computer every time you attend the lab;
4. Make a folder with your name and save the programs you perform at
this folder, (this important for your evaluation).
4
Part One
Lab. No. 1
5
1. Command Window
6
2. Command History
• In this window, we can view previously used functions, and copy and
execute selected lines.
7
3. Launch Pad
• MATLAB’s Launch Pad provides easy access to tools, demos, and documentation.
8
4. Help browser
• The Help browser is used to search and view documentation for all your
Math Works products.
• To open the Help browser, click the help button in the toolbar, or Type
helpbrowser in the Command Window.
9
5. MATLAB Workspace
10
6. Current Directory Browser
• MATLAB file operations use the current directory and the search
path as reference points.
• Any file you want to run must either be in the current directory
or on the search path.
11
2. Enter the following matrix,
A=1 3 4 2
2 0 1 6
4 1 2 7
(a) Get the matrix size
(b) Get the matrix transpose
4. If V1 = 5v, V2 = 6v, Z11=2, Z12=1, Z21=3 Z22=4, get the value of I1 and I2?
Lab. No. 2
13
Lab No. 3
14
15
16
17
18
Lab No. 4
Function File
The input to the function is x and the output is f(x). Use the function to
calculate:
a) f(x) for x = 6.
b) f(x) for x = 1, 3, 5, 7, 9, and 11.
3. plot, xlabel, ylabel, title, and axis commands;
20
5. bar plot command
6. pie plot
21
7. Write an m-file to give the following figure?
figure no. 1 figure no. 2
1 1
z = cos(x)
y = sin(x)
0 0
-1 -1
0 2 4 6 0 2 4 6
x-axis x-axis
figure no. 3
1
m = exp(-x)
0.5
0
0 1 2 3 4 5 6 7
x-axis
22
8. Write an m-file to give the following figure?
figure no. 1
1
y = sin(x)
0
-1
0 1 2 3 4 5 6
x-axis
figure no. 2 figure no. 3
1 1
m = exp(-x)
z = cos(x)
0 0.5
-1 0
0 2 4 6 0 5 10
x-axis x-axis
23
Lab No. 5
Q1. What is meant by relational and logical operators, give examples?
Q.2 The following were the daily maximum temperatures (in F): 58 73 73 53
50 48 56 73 73 66 69 63 74 82 84 91 93 89 91 80 59 69 56 64 63 66 64 74 63
69. Use relational and logical operations to determine the following:
Q.3
Q.4 A 3-bit A/D converter, with an analog input x and digital output y, is
represented by the equation:
24
Lab No. 6
Q.1 Determine the number of consecutive integer numbers which when added
together will give a value equal to or just less than 210.
---------------------------------------------------------------------------------------------------
Q.2
---------------------------------------------------------------------------------------------------
Q.3 If we have the following roots of the polynomial, r = 6.5 4 2.3 -1.2 0.5 find
the polynomial?
---------------------------------------------------------------------------------------------------
Q.4 we have
Find
a) f1(x) + f2(x)
b) f1(x) * f2(x)
---------------------------------------------------------------------------------------------------
Q.5 Divide
a)
b) by
25
Part Two
Simulink
Introduction
• Simulink is a graphical extension to MATLAB for the modeling and
simulation of systems.
• In Simulink, systems are drawn on screen as block diagrams. Many
elements of block diagrams are available (such as transfer functions,
summing junctions, etc.), as well as virtual input devices (such as
function generators) and output devices (such as oscilloscopes).
Simulink is integrated with MATLAB and data can be easily
transferred between the programs.
• In this part, we will introduce the basics of using Simulink to model and
simulate a system.
• Simulink is supported on Unix, Macintosh, and Windows environments,
and it is included in the student version of MATLAB for personal
computers.
26
Starting Simulink
• Simulink is started from the MATLAB command prompt by entering
the following command:
>> Simulink
27
The Simulink Library Browser window should now appear on the screen.
Most of the blocks needed for modeling basic systems can be found in the
subfolders of the main "Simulink" folder (opened by clicking on the "+" in
front of "Simulink"). Once the "Simulink" folder has been opened, the
Library Browser window should look like:
Building a System
1. 1st Model
To demonstrate how a system is represented using Simulink, we will build the
block diagram for a simple model consisting of a sinusoidal input multiplied
by a constant gain, which is shown below:
28
This model will consist of three blocks: Sine Wave, Gain, and Scope. The Sine
Wave is a Source Block from which a sinusoidal input signal originates. This
signal is transferred through a line in the direction indicated by the arrow to the
Gain Math Block. The Gain block modifies its input signal (multiplies it by a
constant value) and outputs a new signal through a line to the Scope block. The
Scope is a Sink Block used to display a signal (much like an oscilloscope).
29
Running Simulations
Now that our model has been constructed, we are ready to simulate the system. To
do this, go to the Simulation menu and click on Start, or just click on the
"Start/Pause Simulation" button in the model window toolbar (looks like the "Play"
button on a VCR). Because our example is a relatively simple model, its simulation
runs almost instantaneously. With more complicated systems, however, you will be
able to see the progress of the simulation by observing its running time in the the
lower box of the model window. Double-click the Scope block to view the output
of the Gain block for the simulation as a function of time. Once the Scope window
appears, click the "Autoscale" button in its toolbar (looks like a pair of binoculars)
to scale the graph to better fit the window. Having done this, you should see the
following:
30
2. 2nd Model
Signal Routing
31
3. 3rd Model
Transfer Functions
32
4. 4th Model
Closed Loop Control System
33
5. 5th Model
Integrators and Derivatives
34