Experiment 1
Experiment 1
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.
• 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.
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;
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
Results:
Q1:
Q2:
Q3: