0% found this document useful (0 votes)
32 views8 pages

Experiment 1

Control Engineering lab

Uploaded by

225037
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)
32 views8 pages

Experiment 1

Control Engineering lab

Uploaded by

225037
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/ 8

Control Engineering Lab

Experiment # 01
Implementation of basic commands/function in MATLAB for Control System
Objectives:
This lab provides an introduction to MATLAB. The lab also provides tutorial of
polynomials, script writing and programming aspect of MATLAB from control systems view
point.
Apparatus:
• Computer having MATLAB software
Theory:
Introduction to MATLAB:
• What is MATLAB?
MATLAB is a computer program that combines computation and visualization power that
makes it particularly useful tool for engineers. MATLAB is an executive program, and a script
can be made with a list of MATLAB commands like other programming language. MATLAB
stands for Matrix Laboratory. The system was designed to make matrix computation
particularly easy.
The MATLAB environment allows the user to:
• Manage variables
• Import and export data
• Perform calculations
• Generate plots
• Develop and manage files for use with MATLAB.
To start MATLAB:
START>>PROGRAMS>>MATLAB 6.5 MATLAB 6.5 or shortcut creation/activation as
shown in Figure 1.1.

Figure 1.1: MATLAB shortcut activation


Graphic (Figure) Window displays plots and graphs created in response to graphics
commands. M-file editor/debugger window create and edit scripts of commands called M-
files. Display windows are shown in Figure 1.2.

Department of Mechanical Engineering, Air University A&AC Kamra 1


Control Engineering Lab

Figure 1.2: Display windows of MATLAB


Type one of following commands in the command window:
• Help– lists all the help topic.
• Helptopic – provides help for the specified topic.
• Helpcommand– provides help for the specified command.
• Help help– provides information on use of the help command.
• Helpwin– opens a separate help window for navigation.
• Lookforkeyword –Search all M-files for keyword.
Variable names:
• Must start with a letter
• May contain only letters, digits, and the underscore “_”
• MATLAB is case sensitive, i.e. one & onE are different variables.
• MATLAB only recognizes the first 31 characters in a variable name.
Assignment statement:
• Variable = number;
• Variable = expression;
MATLAB Code:
tutorial = 1234;
tutorial = 1234
tutorial =
1234
NOTE: When a semi-colon”;” is placed at the end of each command, the result is not
displayed.
Special variables:
• ans: default variable name for the result
• pi:π= 3.1415926…………
• eps:€= 2.2204e-016, smallest amount by which 2 numbers can differ.
• Inforinf:∞, infinity
• NaNor nan: not-a-number
Commands involving variables:
• who: lists the names of defined variables
• whos: lists the names and sizes of defined variables
• clear: clears all varialbes, reset the default values of special variables.

Department of Mechanical Engineering, Air University A&AC Kamra 2


Control Engineering Lab

• clearname: clears the variable name


• clc: clears the command window
• clf: clears the current figure and the graph window.

• Matrices
A Matrix array is two-dimensional, having both multiple rows and multiple columns,
similar to vector arrays:
• It begins with [, and end with].
• Spaces or commas are used to separate elements in a row.
• Semicolon or enter is used to separate rows. Here A is an m x n matrix.

MATLAB Code:
f = [ 1 2 3; 4 5 6] h=[246 h=
f =1 2 3 1 3 5] 246
456 135
Plotting:
For more information on 2-D plotting, type help graph2d
Plotting a point:
plot ( variablename, ‘symbol’)
The function plot () creates a graphics window, called a Figure window, and named by
default “Figure No. 1”
MATLAB Code:
z = 1 + 0.5j;
plot (z, ‘.’)
Output is shown in Figure 1.3.

Department of Mechanical Engineering, Air University A&AC Kamra 3


Control Engineering Lab

Plotting Curves:
• Plot (x,y)– generates a linear plot of the values of x (horizontal axis) and y (vertical axis).
• Semilogx (x,y)– generate a plot of the values of x and y using a logarithmic scale for
xand a linear scale for y
• Semilogy (x,y)– generate a plot of the values of x and y using a linear scale for x and a
logarithmic scale for y.
• Loglog(x,y) – generate a plot of the values of x and y using logarithmic scales for both x
and y.
Multiple Curves:
• Plot (x, y, w, z) –multiple curves can be plotted on the same graph by using multiple
arguments in a plot command. The variables x, y, w, and z are vectors. Two curves will
be plotted: y vs. x, and z vs. w.
• Legend (‘string1’, ‘string2’,…) – used to distinguish between plots on the same graph
Multiple Figures:
• Figure (n)–used in creation of multiple plot windows. Place this command before the
plot() command, and the corresponding figure will be labeled as “Figure n”.
• Close – closes the figure n window.
• Close all – closes all the figure windows.
Subplots:
• Subplot (m, n, p)– m by n grid of windows, with p specifying the current plot as the pth
window.
Sample: (polynomial function)
Plot the polynomial using linear/linear scale, log/linear scale, linear/log scale, & log/log scale:
y = 2x2+ 7x + 9
% Generate the polynomial:
x = linspace (0, 10, 100);
y = 2*x.^2 + 7*x + 9;
% plotting the polynomial:
figure (1);
subplot (2,2,1), plot (x,y);
title ('Polynomial, linear/linear scale');
ylabel ('y'), grid;
subplot (2,2,2), semilogx (x,y);
title ('Polynomial, log/linear scale');
ylabel ('y'), grid;
subplot (2,2,3), semilogy (x,y);
title ('Polynomial, linear/log scale');
xlabel('x'), ylabel ('y'), grid;

Department of Mechanical Engineering, Air University A&AC Kamra


4
Control Engineering Lab

subplot (2,2,4), loglog (x,y);


title ('Polynomial, log/log scale');
xlabel('x'); ylabel ('y'); grid;
Output: Output is shown in Figure 1.4.

Lab Tasks

Q1: Consider the two polynomials p(s)=s2+2s+1 and q(s)=s+1. Apply MATLAB/Simulink to
model selected control system also Execute the command.
a. p(s)*q(s)
b. Roots of p(s) and q(s)
c. p(-1) and q(6)
Q2: Apply MATLAB command to find the partial fraction of the following and also Execute the
command.
𝐵(𝑠) 2𝑠3 +5𝑠2 +3𝑠+6
a) =
𝐴(𝑠) 𝑠3 +6𝑠2 +11𝑠+6

𝐵(𝑠) 𝑠2 +2𝑠+3
b) =
𝐴(𝑠) (𝑠+1)3

Q3: MATLAB M-file Script


Apply MATLAB to generate the first 100 terms in the sequence a(n)define recursively by
a(n+1)=p*a(n)*(1-a(n))
with p=2.9 and a(1) = 0.5. And also Execute the command.

Department of Mechanical Engineering, Air University A&AC Kamra


5
Control Engineering Lab

Results:

Q1:

Department of Mechanical Engineering, Air University A&AC Kamra


6
Control Engineering Lab

Q2:

Department of Mechanical Engineering, Air University A&AC Kamra


7
Control Engineering Lab

Q3:

Department of Mechanical Engineering, Air University A&AC Kamra


8

You might also like