Uploaded by Badr

Control System Lab Manual ENRG405L T2201 2020 1ED

advertisement
MECHANICAL AND ENERGY
ENGINEERING DEPARTMENT
CONTROL SYSTEM LAB
LAB MANUAL
1st Edition
Prepared by:
Eng. Mohammed AlMutawa
2020
Table of Contents
Table of Contents ...................................................................................................................... 1
Laboratory Safety ...................................................................................................................... 2
Guideline for Lab report writing ................................................................................................ 4
1.
Experiment 1: Introduction to the computer-aided design package MATLAB ............. 6
2.
Experiment 2: Introduction to the computer-aided design package MATLAB (Part 2 &
Part 3) 22
3.
Experiment 3: MATLAB/Simulink tutorials in modeling dynamic systems (Part 1) .... 30
4.
Experiment 4: MATLAB/Simulink tutorials in modeling dynamic systems (Part 2) .... 37
5.
Experiment 5: Introduction to Simulink and Simulation of a Speed Control System.. 45
6.
Experiment 6: Simulation of a Prototypes Second Order System (Part 1) .................. 53
7.
Experiment 7: Simulation of a Prototypes Second Order System (Part 2) .................. 67
8.
Experiment 8: Study PID Controller on a Simple Mechanical System ......................... 70
9.
Experiment 9: Design Feedback Controllers using Root Locus Technique for a Specific
Performance Parameter .......................................................................................................... 82
10.
APPENDIX A: ABET Student Outcome 6 Assessment Rubric ................................... 89
11.
APPENDIX B: Mechanical and Electrical Laws for Deriving Dynamic Module ......... 90
12.
APPENDIX C: Creating Multiple Curves in One Plot using For Loop ........................ 91
13.
APPENDIX D: MATLAB Basic and Control Systems Commands ............................... 93
References ............................................................................................................................. 128
1
Laboratory Safety
Good laboratory technique is not only the sign of professional superiority but also
allow us to prevent most serious and harmful accidents. Good techniques include
proper handling of chemicals, glassware and instruments, and always habitual use of
safety precautions.
General safety rules
1.
The laboratory manual is required for anyone to be in the laboratory every
time.
2.
No equipment is to be operated until the approval of the instructor. Only the
equipment belong to the assigned experiment is to be operated. All members
of a group are to be properly informed on the safety aspects of their assigned
experiment and to be familiar with the safety aspects of surrounding
experiments
3.
Safety glasses with side shields or safety goggles (when handling hazardous
chemicals). Neckties, dangling clothing or jewelry, and other unsafe items are
prohibited. Long pants are recommended.
4.
Sleeping and eating is prohibited in the laboratory. Violation of this rule will
result in dismissal from the laboratory for that day and an unexcused absence.
5.
The safety precautions in the experimental plan must be followed.
6.
No operating equipment will be left unattended. At least two members of the
group must be present while the equipment is operating.
7.
The laboratory floor must be kept dry, clean, and uncluttered at all times. Any
spills should be cleaned up immediately.
8.
All chemicals must be transported in a safety carrier. All mercury and alcohol
thermo meters and more than one item of glassware must be transported in a
bucket or other suitable container.
9.
Any accident or hazardous situation must be reported to the Laboratory
Supervisor immediately.
Personal protective equipment
1.
A dust mask should be worn when handling powdery solids.
2.
Earplugs protect the ears against high-decibel noise (90 dBA or above).
3.
Safety glasses with side shields or safety goggles are to be worn at all times in
the laboratory.
4.
Contact Lenses are discouraged in the laboratory.
5.
Ventilated shoes and sandals are recommended
6.
Insulated gloves are required to avoid burns when operating steam valves and
when handling hot objects.
7.
Rubber or other protective gloves are required to avoid contact with chemicals
that can burn or penetrate the skin.
2
8.
Long pants (recommended). no neckties, no dangling clothes nor dangling
jewelry.
9.
Buttoned long sleeve shirts (recommended).
10.
Long-sleeve laboratory coat when handling chemicals that can burn the skin or
be absorbed through the skin.
General equipment safety
Chemical safety
1.
Transport all chemicals using a safety carrier. The chemical must be in a
closed container.
2.
Flammable, volatile chemicals are to be stored in the Flammable Liquids
Storage Cabinet.
3.
Use a Class B Fire Extinguisher for chemical fires.
4.
Wear protective gloves and apron when handling strong acids and bases.
5.
Store oxidizable materials away from acids and bases.
Electrical safety
1.
Use the “left-hand” rule in operating power boxes, i.e. use the left hand to
move the handle up or down.
2.
Power must be off before making electrical connections.
3.
Avoid splashing or spraying water on electrical connections, wall sockets, and
junction or power boxes.
4.
Use a Class C Fire Extinguisher if energized electrical systems are involved.
Personal hygiene practices
1.
Wash hands before and after running an experiment.
2.
Wear gloves appropriate for the experiment. Clean the gloves after using
them.
3.
Cover any cuts or open wounds with clean, suitable material.
4.
Do not apply cosmetics while in the laboratory.
5.
Keep extra clothing available so that you can change after working in the
laboratory or in case your clothes become contaminated.
6.
Use a pipette bulb; do not use your mouth to pipette.
3
Guideline for Lab report writing
1.
Cover Page
Write the Name of your University, School, Department, Subject name then Identify
yourself and your partner/s, write you ID number, Date of Performing the experiment,
Date of Submitting the report.
2.
Introduction/ General Information
Based on your text books, write about the subject of the experiment, an introduction
has been already included so you may either add to it or you can write a new one. You
need to paraphrase any material you take from the manual.
3.
Purpose/ Objective
This gives the objective of the Experiment. What concept or skill was highlighted by
this experiment? Ask yourself, “Why did we do this activity? What was I supposed to
learn or practice?” Sometimes the purpose can be stated in one sentence. Other times
it may be necessary to add some extra information to narrow the scope of the activity.
4.
Materials & Reagents
Include lists the materials that were needed to carry out this activity. This could also
be in the form of a table.
5.
Procedure
All you are trying to convey is a mental picture of what you did. Ordinal phrases are
not necessary. The order of events is conveyed by the sentence order in the
description. Remember that your audience should be able to repeat your procedure if
they wish to do so. Write your description of what was done so that the reader can
visualize the set-up. Be sure to include reference to any equipment that you used (The
mass was taken on a balance.)
6.
Observations & Data
This includes both quantitative (numerical) and qualitative (sensual, not emotional)
observations. Quantitative observations are best presented in data tables.
7.
Analysis of Data/ Results
This is the section where you will show any calculations that you made using the data
you collected.
4
Give the formula you will use for each type of calculation. You should show which
measurements you are plugging into each calculation and then show the solution.
Once you have shown a sample calculation, you may use a data table to show other
calculated values of the same type.
Include graphs and their calculations
This is the proper place to discuss anything that happened during the activity that
may have affected your measurements.
Mention the sources of error, and their effect on the results that were attained during
the experiment.
8.
Discussion
State the answers to all the questions included at the end of each experiment.
9.
Conclusions
This is the section of your report where you discuss how the purpose of the activity
relates to the analysis of your data. In other words, what did you learn?
Stick to the facts; do not comment on whether you enjoyed the activity. Be specific in
your statements. If the results of the activity were not satisfactory, suggest how the
activity could be improved to give better data. Did the activity raise questions that
cannot be answered with the data you collected? This is the place to mention them.
Remember, conclusions are connections that are not obvious on the surface.
5
Experiment 1: Introduction to the computer-aided design package MATLAB
1.
Objectives
The purpose of this experiment is to gain the basic knowledge and understanding of what
MATLAB is and how to use it. Also, it aimed to practice each new command by completing the
examples, exercise, and study how to define variables, matrices, etc, see how we can plot
results, and write simple MATLAB codes.
The objectives can be summarized below:
1.
To get familiar with MATLAB in general and basic commands.
2.
To introduce a Computer-Aided Design (CAD) package MATLAB.
3.
To be able to solve simple problems using MATLAB.
4.
Theoretical Background
In addition to the simple background provided here, students are requested to read the
hand-out provided for MATLAB and MATLAB slides.
MATLAB stands for Matrix Laboratory is programming software that can do the numerical
computation, allow the user to develop algorithms and apply data analysis of their finding,
and also can visually show their result.
1.
2.
3.
MATLAB → stand for Matrix Laboratory
A high-performance language for technical computing
Founded by MathWorks, Inc → 1984
4.
Typical uses of MATLAB
1.
Mathematical computations
2.
Algorithmic development
3.
Model prototyping (prior to complex model development)
4.
Data analysis and exploration of data (visualization)
5.
Scientific and engineering graphics for a presentation
5.
The reason that MATLAB has replaced other technical computational languages
1.
MATLAB is based on simple and easy-to-use programming tools
2.
graphic facilities
3.
built-in functions and
4.
an extensive number of toolboxes.
MATLAB windows view
6
Figure Error! No text of specified style in document..1: MATLAB Main Window
Here the usage of these windows:
Command window: allow the user to write commands and codes as individual statements
and get the result at the same window after pressing enter. It is like the view of a normal
calculator. Error! Reference source not found.
M-File: is a text or script file that allows the user to write freely his codes and commands
completely to form a whole structure of an algorithm and then later the user will be able to
run the whole code at once.
Work-space: is the place where all variables (define during coding in m-file or command
window) is stored or any imported data.
Command History: This is the log statements stored during the last sessions on MATLAB.
Current folder: allow the user to show and search for his files (or destination) in an
interactive way
Details: show some details of the current folder.
Basic Commands
The below table summarizes the basic command of MATLAB. It is also there in the
Appendix D in Table Error! No text of specified style in document..36 for your
convenience.
Table Error! No text of specified style in document..1: Basic Commands used in MATLAB
#
Command
Usage
Example
1
help
It will provide you wthe
nessary information of any
command in MATLAB or
related topics to that
command/function and will
display the help text in the
>> help sin
sin Sine of argument in
radians.
sin(X) is the sine of the
7
Command Window.
elements of X.
See also asin, sind, sinpi.
Reference page for sin
Other functions named sin
2
clc
Clear command window.
3
clear all
removes all variables, globals,
functions and MEX links.
4
close all
closes all the open figure
windows.
5
close(F)
Closes figure F
6
whos
returns a structure with the
fields: name, size, bytes, etc…
7
ans
Variable store the last result of 2*3
your command window
ans =
execution.
6
8
( ), ^, *, /, +, -
The basic mathematical
operations and parentheses.
The priority of operation can
be summarized in this word
“PEMDAS”:
PEMDAS
%{
Write and calculate the
mathematical expression below:
2 × 102 − 0.57
25
P: parentheses
E: exponential
2.5
%}
M: multiplication
D: division
A: addition
S: subtraction
(2*10^-2-0.57)/2^5^2.5
%{
ans =
-9.4948e-05
%{
% However it is a good practice
to use
% parentheses as much as you
can to make it
% simple to read, even if the
priority is met.
(2*10^-2-0.57)/(2^5^2.5)
8
%{
ans =
-9.4948e-05
%{
3-2^4
(3*2)^4
3-2^4
8/2^4
2^4\8
9
i
j
Reserved word/letter for
i
complex number ⅈ = √−1 and
%{
𝑗 = √−1 .
ans =
0.0000 + 1.0000i
%{
10 a1 = [1 2 3]
a2 = [1, 2, 3]
Creating a 1x3 (row) vector in a1= [1 2 3]
two different ways.
a2 = [1, 2, 3]
%{
a=
1
2
3
2
3
a2 =
1
%}
11 b1 = [1
2
Creating a 3x1 (column) vector b1 = [1
in two different ways.
2
3]
3]
b2 = [1; 2; 3]
b2 = [1; 2; 3]
%{
b1 =
1
2
9
3
b2 =
1
2
3
%}
12 A = [33, 21; 41, 10]
Creating a 2x2 matrix
A = [33, 21; 41, 10]
%{
A=
33 21
41 10
%}
13 A(2) = 5
Accessing the 1-D indexing to A = [33, 21; 41, 10]
the second element counting
A(2) = 5
from the first column going
down. Then changing its
%{
content to a value of 5.
A=
33 21
5 10
%}
14 a + b
if we add two vectors/matrixes a = [2 3 4]
we need to have a matching
b= [6 8 7]
size. The adding will be an
element by element addition. a + b
%{
ans =
8 11 11
%}
15 a – b
if we subtract two
a = [2 3 4]
vectors/matrixes we need to
b= [6 8 7]
have a matching size. The
addition will be an element by a -b
element manner.
%{
ans =
10
-4 -5 -3
%}
16 a.*b
if we elementwise multiply
a = [2 3 4]
two vectors/matrixes we need
b= [6 8 7]
to have a matching size. The
multiplication will be an
a .*b
element by element manner.
%{
ans =
12 24 28
%}
17 a./b
Element by elment division
a = [2 3 4]
b= [6 8 7]
a ./b
%{
ans =
0.3333 0.3750 0.5714
%}
18 a^n
a^2
Normal/matrix power of a, or a=[2 3; 5 8]
rising the matrix a to the
a^2
power n or 2.
%{
Note: here we need to
consider the condition of
matrix multiplication, which is
the number of columns of the
first matrix should equal the ans =
number of rows of the second
19 30
matrix.
50 79
%}
19 a.^n
a.^2
Elementwise power of a.
a=[2 3; 5 8]
a.^2
%{
ans =
4
9
25 64
11
%}
20 a'
Transpose of a vector/matrix a=[2 3; 5 8]
(only if it is not a complex
a’
number). However, if it is a
complex number then it will be %{
a transpose of a conjugate of
ans =
that complex number.
2
5
3
8
%}
a=[3+6i 2-8i]
A= a'
%{
ans =
3.0000 - 6.0000i
2.0000 + 8.0000i
%}
21 a.'
Transpose of a vector/matrix
a=[3+6i 2-8i]
A= a.'
%{
ans =
3.0000 + 6.0000i
2.0000 - 8.0000i
%}
22 a = 4:10
The colon generates a
a = 4:10
sequence of numbers from 4
%{
to 10 with a default increment
of 1.
a=
4
5
6
7
8
9
10
%}
23 a = 4:2:10
a=4:2:9
The colon generates a
sequence of numbers from 4
to 10 with an increment of 2.
a = 4:2:10
%{
a=
4
6
8 10
12
%}
a=4:2:9
%{
a=
4
6
8
%}
24 a = 10:-1:4
The colon generates a
sequence of numbers from 10
to 4 with a decrement of 1.
25 linespace(a,b,n)
Generates linearly spaced
linspace(2,10,5)
vectors starting by a end by b
%{
and has n element
ans =
a: staring point, b: ending
point,
2 4 6 8 10
26 x(:)
n: number of elements
%}
Taking all the elements of R
and stacking all the columns
one after the other in a onecolumn vector.
x= [2 3 ;7 8 ; 2 44 ]
x(:)
%{
x=
2
3
7
8
2 44
ans =
2
7
2
3
8
13
44
%}
27 R(n:end)
All the elements from nth to
the last element.
28 R(2:5)
All the elements from 2nd to
the 5th element of R
R= [2 3 5 70;7 8 10 40; 2 44 90
79]
R(2:5)
%{
ans =
7
2
3
8
%}
29 R(3,1)
Accessing the element located R= [2 3 5 70;7 8 10 40; 2 44 90
in the 3rd row and 1st column. 79]
R(3,1)
%{
ans =
7
2
3
8
%}
30 R(n,:)
All the elements of the row
number n. (all n row elements)
31 R(:,n)
All the elements of the column
number n. (all n column
elements)
32 diag(R)
All the diagonal elements of R
33 R(2,2:4)
The elements of row 2 from
column number 2 to column
number 4
R= [2 3 5 70;7 8 10 40; 2 44 90
79]
R(2,2:4)
%{
ans =
8 10 40
%}
34 end
represents the last index of an B=[5 7 1 8 3;
array.
9 6 4 2 5 ];
14
B(1,2:end)
means: select the elements
from the second column to the
last column of the first row in a
matrix B
35 [ ]
:
36 length(R)
37 size(R)
size(R,1)
size(R,2)
38 find(condition)
Using an empty square bracket B(3,:) = [ ];
and colon can delete a certain
means: delete the third row of
row or column in a matrix.
matrix B, or in other words fix
row 3 and move to all columns
to delete those elements.
Length of largest array
dimension in R
length(R)
ans = 4
Size of array R. Where the
size(R)
output is a vector of two
%{
elements. The first element
represents the number of rows ans =
and the second one represents
3 4
the number of columns.
size(R,1) gives the number of %}
rows only. size(R,2) gives the
number of columns only.
Return a column of 1D indices X=[ 1
of elemnts those satisfying the
0
input condition
0
0
2;
1
1;
0
4]
> find(X)
ans =
1
5
7
8
9
x=-8:0.1:8;
y=(-(x).^2+10);
plot(x,y)
a=find(y>=max(y))
15
39 [r c] = find()
Returns 2D indices of elements [r c] = find(X)
that satisfy the input condition
a=
r: column vector contains
1
row’s numbers
2
c: column vector contains
column’s numbers
1
2
3
b=
1
2
3
3
3
40 [A, B]
Concatenates horizontally
41 [A; B]
Concatenates vertically
42 char1='hello world this is Creating a character vector
Mohammed'
with the name char1. The size
of this vector is 1 x 28.
43 char2='Ahmed'
Creating a character vector
with the name char2. The size
of this vector is 1 x 5.
45 str1="hello world this is
Mohammed"
Creating a scaler string with
the name str1. The size of this
vector is 1 x 1.
46 str2="Ahmed"
Creating a scaler string with
str2="Ahmed"
the name str2. The size of this
%{
vector is 1 x 1.
str2 =
"Ahmed"
%}
47 str3=["Ahmed",”Omar”]
Creating a vector string with
the name str3.
str3=["Ahmed",”Omar”]
%{
16
str3 =
1×2 string array
"Ahmed" "Omar"
%}
48 num2str(num1)
“converts a numeric array into num1=90
a character array that
NS1=num2str(num1)
represents the numbers” [1]
%{
Usually used for title and
legend.
num1 =
90
NS1 =
'90'
%}
char7=['I got ',NS1,' in my final
exam of dynamic course out of
100']
49 x=Input(‘Enter
Something’)
“displays the text
prompt = 'Enter a Number: ';
in prompt and waits for the
x = input(prompt)
user to input a value and press
the Return key” [1]
y = x*10
50 plot( x,y )
2-D line plot
x,y : could be any variable
plotting x Vs. y
51 xlabel(‘Text’)
x = 0: 0.01:2*pi;
y = sin(x);
plot(x,y)
Label x-axis
xlabel(‘Angle in Radeon’)
Label y-axis
ylabel(‘Amplitude’)
Add legend to axes
legend('cos(x)','cos(2x)')
Text: could be any text or
string
52 ylabel(‘Text’)
Text: could be any text or
string
53 legend(‘Text’)
Text: could be any text or
string
17
54 title(‘Text’)
Add a title to the figure
title(‘Sine Vs its Angle in
Radeon’)
Create a figure with index n
window.
figure(1)
Text: could be any text or
string
55 figure (n)
x = 0: 0.01:2*pi;
Note: it is useful when you
y1 = sin(x);
create multiple plots in a
supported window like in the plot(x,y1)
example
figure(2)
x = 0: 0.01:2*pi;
y2 = cos(x);
plot(x,y2)
56 grid on
Display axes grid lines
57 subplot(m,n,p)
divides the current figure into x = 0:0.1:2*pi;
an m-by-n grid and creates
y1=sin(x);
axes in the position specified
by p
y2=sin(2*x);
m, n, p : can be changed
y3=sin(4*x);
subplot(2,2,1)
plot(x,y1,'--')
xlabel('t')
ylabel('Amplitude')
title('y1')
grid on
subplot(2,2,2)
plot(x,y2,':')
xlabel('t')
ylabel('Amplitude')
title('y2')
grid on
18
subplot(2,2,[3 4])
plot(x,y3,':')
xlabel('t')
ylabel('Amplitude')
title('y3')
grid on
58 xlim([a b])
specifies the x-axis limits for
the current axes. Where a is
the lower limit and b is the
upper limit of the x-axis [1].
59 ylim([c d])
specifies the y-axis limits for
the current axes. Where c is
the lower limit and d is the
upper lmit of the y-axis [1].
60 axis([a b c d])
sets scaling for the x- and yaxes on the current plot [1].
6.
Experimental Apparatus
You need a computer with MATLAB software installed on it.
7.
Experiment Work
Explorer the new commands learn in the lab on Table Error! No text of specified style in
document..1 and tray to familiarize yourself of their function and how can be used to perform the
simple mathematical operation, and to plot a given data scientifically. Then answer the following
questions:
Q1: MATLAB stand for…. [Chose]
1.
Mathematical Laboratory
2.
Macro Telecommunication Laboratory.
3.
Machine Autonomic Telecom Laboratory.
4.
Matrix Laboratory
Q2: MATLAB is only used for engineering [True/False].
Q3: Clear all will…….
1.
Clean the commend window.
19
2.
Clean all vectors and variables stored in MATLAB.
3.
Will disappear the figure windows
4.
Will close the MATLAB m file.
Q4: To build a long algorithm it is better to use commend window instead of m file in
MATLAB [True/False]
Q5: The right way to create a column vector for the following elements 3, 10, 110 is……..
1.
A= [1 2 3]
2.
A = [1 2 3]’
3.
A=[1;2;3]
4.
Both (b) and (c)
Q6: The correct way to get a sequence of numbers in an array (or vector) with a specific
increment is…..
1.
B = 11;2;100
2.
B=11:2:100
3.
B= [11 2 100]
4.
B=linspace(11,2,100)
Q7: comment on every line of code for the following below codes in Table Error! No text of
specified style in document..2 and describe the overall function of the code and modify it
to get a batter result:
Table Error! No text of specified style in document..2: Simple Code for Review
Code
Comment here
clear all
------------------------------------------------------
close all
------------------------------------------------------
clc
------------------------------------------------------
x= 0:0.1:2*pi
------------------------------------------------------
y=sin(x)
------------------------------------------------------
plot(x,y)
------------------------------------------------------
title(‘sine wave Vs Time’)
------------------------------------------------------
ylabel(‘Sine values’)
------------------------------------------------------
xlabel(‘Time’)
------------------------------------------------------
grid on
-----------------------------------------------------20
Overall Function of the code
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
21
Experiment 2: Introduction to the computer-aided design package MATLAB (Part 2 & Part 3)
1.
Objectives
This experiment will be focused on providing different practical exercises for students to perform
using MATLAB. Working through these examples will train students to perform the basic
mathematical operation and basic code flow structure. Also, to teach students how to build user
define functions.
The objectives/skills/concepts can be summarized below:
2.
Mathematical operation in MATLAB.
3.
Data representation and plotting.
4.
Logical operation in MATLAB.
5.
Creating vectors and matrixes.
6.
If statement.
7.
For loop structure.
8.
While loop structure.
9.
Case structure
10.
User define function
11.
Theoretical Background
In addition to the simple background provided in last experiment, students are requested to
read the hand-out provided for MATLAB and MATLAB slides. Also, review Appendix D.
12.
Experimental Apparatus
You need a computer with MATLAB installed on it.
13.
Experiment Work
The .m file provided at the beginning of the lab contains new commends and some examples that
will show you different usages of that commend and how MATLAB understand the logic
operation, relations, conditional statements, for-loop structure, vector, and matrix generation,
etc…. Then answer the following questions.
Q1: Define the following Vectors:
A = [2 3 4 7 9 11];
B = [11 15 32 46 10 60];
a. Multiply A by B in a dot product, that is multiplying the first element of the vector to the
first element of the second vector and so on without adding up the resulting multiplication
and store the result in a vector called AB.
Table Error! No text of specified style in document..3
Place your code to
the right
22
Place your results
(execution of the
code) to the right
b. Multiply A by B in a cross product and store the result on vector AXB. You need to do
some modification in either of the two vectors before you do the multiplication. Explain
yourself why you do that?
Table Error! No text of specified style in document..4
Place your code to
the right
Place your results
(execution of the
code) to the right
Explain yourself on
part ‘b’ for any
modification
required
…………………………………………………………………………………………………………
Compare your
result on part ‘a’
and ‘b’
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Q2: You have five scores of students in an engineering class with the following vector:
C = [80 40 50 90 70];
Name another vector “score” which is equal to the vector C to make it readable.
a. Find the highest score
b. Find the lowest score
c. Find the average of the class
Table Error! No text of specified style in document..5
Place your code to the
right
23
Place your execution
of the code to the
right
Q3: You have a 2-D plane of an iron that is heated up in the right bottom corner. The
temperature of this 2-D plane across the area of the foil. By heat conduction, the
temperature will start to spread into the plane as indicated in the 3 by 3 matrix below:
58 61 64
𝑇𝑐 = [ 63 70 88 ] ℃
75 95 100
One of your American guy want to read this data, but he prefers Fahrenheit measurement.
a. So, you need to convert it using the following formula: Tf = Tc *9/5 + 32 ℉
Table Error! No text of specified style in document..6
Place your code to
the right
Place your execution
of the code to the
right
b. Using matrix indexing only, find the following sub-matrix from the matrix Tc that contains
the following elements:
sub𝑇𝑐 = [70
88 ]
95 100
24
Table Error! No text of specified style in document..7
Place your code to
the right
Place your execution
of the code to the
right
c. Using find( ) function, find the index of the elements that exceed 80 ℃. Store the
1D indexing to the value “indxup80”
Table Error! No text of specified style in document..8
Place your code to
the right
Place your execution
of the code to the
right
Q4. An astronaut wants to calculate his weight (in Newtons) for different plants that has
different gravitation constant as follows:
DiffGrav = [11.15, 10.44, 9.798, 8.87]
Which is the gravitation constant vector for the following plants: Neptune, Saturn, Earth and
Uranus respectively.
You need to do the following step
a. First assign a constant for the mass of an astronaut m equal to 60 kg
b. Find astronaut’s new weights by using the second Law of Newton (Hint: F=m*g), and
assign it to a vector let say AstrWeights
c. Generate a zero matrix with a size of 4 by 2 that will be the table for the astronaut new
weight and the second column for the four gravitational constants and name the matrix
DifferentWights
d. After you find the new weights which will be stored in AstrWeights vector you should
assign the first column of the Matrix DifferentWights that is ∎ to AstrWeights and the
25
second column that is ∆ with the gravitation constant vector DiffGrav [Hint: using matrix
indexing]
𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭𝐖𝐢𝐠𝐡𝐭𝐬
∎
∎
= ∎
[∎
∆
∆
∆
∆]
Table Error! No text of specified style in document..9
Place your code to
the right
Place your execution
of the code to the
right
Q5: Plot of the following two functions:
𝒚𝟏 = 𝒄𝒐𝒔𝟐 (𝒙) + 𝒄𝒐𝒔(𝒙), with blue solid line
&
𝟐 (𝟐
𝒚𝟐 = 𝒄𝒐𝒔
∗ 𝒙) + 𝒄𝒐𝒔(𝟐 ∗ 𝒙), with red dashed line
a. Plot y1, and y2 in the same plot of figure(1) window. Show both functions with a range of
twice the period of cosine and with grid.
b. Change the line width using “LineWidth” commend inside plot argument of the two
graphs with a size of 3
c. Make sure to place a title with a name of: “Function 1 and Function 2 Plots”
d. Make sure to place xlabel representing time and ylabel representing sinusoidal function
e. Make sure to place legends for y1 and y2. Let say “y1” and “y2” respectively.
f. Make figure(2) in another window and plot y1, y2, and y3=y1+y2 in a subplot as in the
Figure Error! No text of specified style in document..2 below:
figure(2)
y1 , blue solid line
y3, green dotted line
y2, red dashed line
Figure Error! No text of specified style in document..2
Show the correct xlabel, ylabel for all three function y1, y2, and y3 and a title for every
function with the names “Function 1”, “Function 2”, and “Function 3” and also a general
one title at the top let say “Three types of Sinusoidal Functions”. [Hint: to plot a general one
26
title at the top of the subplot, you need to use this commend sgtitle(‘Your Text Here’). You
need to place this commend after calling subplot in your code]
Table Error! No text of specified style in document..10
Place your code
to the right
Place your
execution of the
code to the right
Q6: Develop a code that will decide to provide a letter grade for a student based on the
following grading criteria of Table Error! No text of specified style in document..11 :
Table Error! No text of specified style in document..11: Grading Criteria
Student Grade Range
Letter Grade
[80,100]
A
[65,80)
B
[55,65)
C
[50,55)
D
[0,50)
F
Use the if-else condition to develop this code and use the variable name “stugrade” as your
main variable for evaluating the conditions. For example, test your code when stugrade =
75. Provide your result in the table below:
Table Error! No text of specified style in document..12
Place your code to
the right
Place your execution
of the code to the
right
27
Q7: Create your own user function that will do the following. The function will represent an
AC voltage signal. The function will take 5 inputs and provide 2 output. The name of the
function will be “VoltAC”. Its inputs and outputs as follow:
vm: (input) maximum voltage or peak voltage
f: (input) frequency of the voltage in Hz
phy: (input) phase shift of the voltage in degree
DCoff: (input) the DC offset voltage in Volt
nsim: (input) the number of simulated periods of the signal
Vac: (output) the output ac voltage signal array generated from the function
tac: (output) the output time generated by the function
The “VoltAC” function have to plot the generated Vac array Vs tac (that is plot commend
shout be inside the function itself). The title of the plot shout be “AC Voltage Vs Time”, and
the x label is “Time in [seconds]” and y label is “voltage in [volts]”. The plot also needs to
have a grid and the line width of the curve should be 3. You need to test your function in the
same .m file with the following setting of the inputs:
Vm = 10 V, f = 60 Hz, phy = 90 degree, DCoff = 5 V, and nsim = 2
Note: make sure you place figure(3) before you test your function. This will be helpful when
you run your whole code instead of run by section.
Table Error! No text of specified style in document..13
Place your code to
the right
Place your
execution of the
code to the right
14.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
28
29
Experiment 3: MATLAB/Simulink tutorials in modeling dynamic systems (Part 1)
1.
Objectives
In this experiment, we will module two different systems using MATLAB. The first system, which
is a mechanical system, has a spring, mass, and viscous damper components. The second system
is a high-pass filter circuit. We will examine and investigate both systems through the differential
equation and finding the transfer function of the systems. For the mass-spring-damper system,
we should use newton’s law ∑F = ma after drawing a free body diagram of the system and
defining the forces to find the system input f(t) and output x(t). Then we will find the state-space
module of that input f(t) and output x(t) by using Ẋ = Ax + Bu to finding Ẋ. Also, will use MATLAB
to find the impulse response of the system for different cases of values of spring, mass, and
viscous damper. Also, we will plot the frequency response of the high-pass filter circuit using
bode commend and find the step response of the system using the “step()” command.
The objectives can be summarized below:
1.
To module some dynamic systems with a differential equation.
2.
To find the transfer function and module it through MATLAB.
3.
To find and module the Stat-Space module of the dynamic systems and
observe the result in MATLAB.
2.
Theoretical Background
In addition to the simple background provided in the first experiment, students are
requested to read the hand-out provided for MATLAB, MATLAB slides, and course lecture
slides. Also, refer to Appendix B to review the physical laws of a mechanical and electrical
systems.
Transfer functions is usually in a form of ratio of complex polynomials as below:
Equation Error! No
text of specified
style in
document..1 [2]
Poles: points in which G(s) → ∞
i.e.: s = -p1, s=-p2, …, s = -pn
Zeros: points in which G(s) = 0
i.e.: s=-z1, s=-z2, …, s=-zm
There can e simple or multiple poles/zeros
N: the order of the system = the order of polynomial in the denominator (characteristic
polynomial)
Some remarks about stat-space representation of a dynamic system:
1.
The dynamic equation, describes the dynamics of the network, is not unique.
2.
This equation could be written in terms of any other network variable.
Below are the key words:
3.
Transfer function (TF):
4.
Zero initial conditions
30
5.
LTI systems
6.
SISO: Single input Single output system
TF = G(S) = C(S)/R(S)
7.
Experimental Apparatus
You need a computer with MATLAB installed on it.
8.
Experiment Work
1. In the simple mass-spring-damper system Figure Error! No text of specified style in
document..3 below (Note: Refair to Appendix B):
1.
Module the system with a differential equation and then find the transfer function
with input f(t) and output x(t).
Figure Error! No text of specified style in document..3: Simple Mass-spring-damper System
[2]
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2.
Find the state-space module of the system in Figure Error! No text of specified style
in document..3 with input f(t) and output x(t).
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------3.
Use MATLAB find the Impulse response of the system for the following cases as in
the table below:
Table Error! No text of specified style in document..14: Case 1: Changing the mass value (m)
Set fv = 0.1, and k=1
Plot the impulse response where M taking the following values
[1, 5, 40]
31
In the same figure number 1
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..4:
Questions:
1. Find the time where the system gets stable at zero value for the three values of M using
the plot.
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. Compare the behavior of the system for the three cases of M and which one has the
highest amplitude? And which one reach its stable final value faster?
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Table Error! No text of specified style in document..15: Case 2: Changing the viscosity value
of the damper (fv)
Set M = 1, and k = 1
Plot the impulse response when fv taking the following values
[0.1, 0.5, 1]
In the same figure number 2
32
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..5:
Questions:
1. Find the time where the system gets stable at zero value for the three values of fv using
the plot.
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. Compare the behavior of the system for the three cases of fv and which one has the
highest amplitude? And which one reach its stable final value faster?
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Table Error! No text of specified style in document..16: Case 3: Changing the spring
constant value (k)
Set M =1 , fv = 0.1
Plot the impulse response when k taking the following values
[1, 5, 10]
33
In the same figure number 3
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..6
Questions:
1. Find the time where the system gets stable at zero value for the three values of k using
the plot.
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. Compare the behavior of the system for the three cases of k and which one has the
highest amplitude? And which one reach its stable final value faster?
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1.
The circuit below in Figure Error! No text of specified style in document..7
represent a high-pass filter using series RC passive components. Follow the steps
below (Note: Refair to Appendix B):
34
Figure Error! No text of specified style in document..7: High-Pass Filter Using RC
Components [2]
1.
Module the system with differential equation and find the TF of the system.
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2.
Design a high-pass filter using series RL circuit as in below Figure Error! No text of
specified style in document..7 with a cutoff frequency of fc=0.2 Hz and R = 2 K𝛺.
(Hint: wc = 1/(R*C) for high pass filter, and wc = 2*pi*fc). Then use MATLAB to plot
the frequency response of the system using bode commend.
% Hint:
opts=bodeoptions;
opts.MagUnits='abs';
opts.FreqUnits='Hz';
bode(TF_BPF)
Your Design Parameters and Assumptions should be clearly indicated below
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
35
{Place your Figure here}
Figure Error! No text of specified style in document..8: Bode plot
3.
Find the step response of the system using the “step()” command in MATLAB
{Place your Figure here}
Figure Error! No text of specified style in document..9
4.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
36
Experiment 4: MATLAB/Simulink tutorials in modeling dynamic systems (Part 2)
1.
Objectives
In this experiment, we will module two different systems using MATLAB. The first system,
which is a car-suspension dynamics system, has two springs, two mass, and viscous damper
components. The second system is a band-pass filter using a series of RLC passive components.
Both systems will be examined and investigated through the differential equation and finding the
transfer function of the systems. For the car-suspension dynamics system, we will find the statespace module from the given information by using Ẋ = Ax + Bu to finding Ẋ. Also, will use
MATLAB to find the impulse response of the system for different cases of values of spring, mass,
and viscous damper. Also, we will plot the frequency response of the bandpass filter using bode
commend and find the step response of the system using the “step()” command.
The objectives can be summarized below:
2.
To module some dynamic systems with a differential equation.
3.
To find the transfer function and module it through MATLAB.
4.
To find and module the Stat-Space module of dynamic systems and observe the
result in MATLAB.
5.
To be able to interpret data from MATLAB
6.
To be able to understand the behavior of a system by changing some parameters in
the system.
7.
To be able to control the system by fixing all parameters variable and observe the
behaver when we change a parameter once at a time.
8.
Theoretical Background
In addition to the simple background provided in experiment 3, students are requested to
read the hand-out provided for MATLAB and MATLAB slides. Also, reviewing lecture slides.
9.
Experimental Apparatus
You need a computer with MATLAB software installed on it.
10.
Experiment Work
1.
For the following car-suspension dynamics in Figure Error! No text of specified style
in document..10 and the state-space representation of the system as Equation
Error! No text of specified style in document..2 below do the following:
Equation Error! No
text of specified
style in
document..2 [2]
37
1.
Simulate using MATLAB for the following cases:
1.
For m1 = 50, m2 =500, ks=20, kw=50, and b=100. Find the state-space
module using MATLAB. Then find the transfer function of the module.
Figure Error! No text of specified style in document..10: Car-Suspension Dynamics [2]
Ans:
Code
{Place your code here}
2.
Result on the MATLAB
{Place your result which is the transfer
function of the system after converting the
stat-space representation into TF
representation. This is the execution results
of the MATLAB code}
Use MATLAB find the Impulse response of the system for the following cases as
below:
Case 1: Set m2= 100, ks=5, kw = 10, and b = 50. Then Plot the impulse response when m1
takes the following values from 10 to 100, with five elements equally spaced in the same
figure with index number 1. Then place your results and observation on Table Error! No text
of specified style in document..17
Ans:
Table Error! No text of specified style in document..17: Case 1: Changing m1
{Place your Figure here}
Figure Error! No text of specified style in document..11
Code
38
{Place your code here}
Q1. Compare the behavior of the system for the five cases of m1 and which one has the
highest amplitude? Also, which one reaches its stable final value faster? (indicate the time
using the plot)?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Case 2: Set m1=10, ks=5, kw = 10, and b = 50. Plot the impulse response when m2 takes the
following values from 100 to 1000, with five elements equally spaced in the same figure with
index number 2. Then place your results and observation on Table Error! No text of
specified style in document..18.
Ans:
Table Error! No text of specified style in document..18: Case 2: Changing m2
{Place your Figure here}
Figure Error! No text of specified style in document..12
Code
{Place your code here}
Q2. Compare the behavior of the system for the five cases of m2 and which one has the
highest amplitude? Also, which one reach its stable final value faster (indicate the time using
the plot)?
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------39
Case 3: Set m1=10,m2=100, ks=5, and kw = 10. Plot the impulse response when b takes the
following values from 50 to 200, with five elements equally spaced in the same figure with
index number 3. Then place your results and observation on Table Error! No text of
specified style in document..19.
Ans:
Table Error! No text of specified style in document..19: Case 3: Changing b
{Place your Figure here}
Figure Error! No text of specified style in document..13
Code
{Place your code here}
Q3. Compare the behavior of the system for the five cases of b and which one has the
highest amplitude? Also, which one reach its stable final value faster (indicate the time using
the plot)?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Case 4: Set m1=10, m2=100, kw = 10, b=50. Plot the impulse response when ks takes the
following values from 5 to 40, with five elements equally spaced in the same figure number
4. Then place your results and observation on Table Error! No text of specified style in
document..20.
Ans:
Table Error! No text of specified style in document..20: Changing ks
{Place your Figure here}
40
Figure Error! No text of specified style in document..14
Code
{Place your code here}
Q4. Compare the behavior of the system for the five cases of ks and which one has the
highest amplitude? Also, which one reach its stable final value faster (indicate the time using
the plot)?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Case 5: Set m1=10, m2=100, ks=5, and b=50. Plot the impulse response when kw takes the
following values from 10 to 100, with five elements equally spaced in the same figure
number 5. Then place your results and observation on Table Error! No text of specified style
in document..21
Ans:
Table Error! No text of specified style in document..21: Case 5: Changing kw
{Place your Figure here}
Figure Error! No text of specified style in document..15
Code
{Place your code here}
Q5. Compare the behavior of the system for the five cases of kw and which one has the
highest amplitude? Also, which one reach its stable final value faster (indicate the time using
the plot the plot)?
---------------------------------------------------------------------------------------------------------------------------
41
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Electrical System
1.
The circuit below represent a band-pass filter using series RLC passive components.
To do the following (Note: Refair to Appendix B):
Figure Error! No text of specified style in document..16: Band-Pass Filter Using Series RLC
Components
1.
Module the system in Figure Error! No text of specified style in
document..16 with differential equation and find the TF of the system.
(Hint: use KVL on the circuit)
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2.
Find the state-space module of the system in Figure Error! No text of
specified style in document..16 (either by mean of simulation or by handwritten derivation).
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------3.
Design a bandpass filter as in Figure Error! No text of specified style in
document..16 with a frequency band of 1 – 10 kHz. (Note: fc1 =1 KHz, and
fc2 = 10 KHz). (Hint: you can select any value of one of the parameters of L,
42
C or R and find the other two. Example select C = 1 µF and from the formulas
given you can find the other values of R and L). Then use MATLAB to plot the
frequency reponse of the system using bode commend.
Hint for the frequency response in MATLAB:
opts=bodeoptions;
opts.MagUnits='abs';
opts.FreqUnits='Hz';
bode(TF_BPF)
Your Design Parameters and Assumptions should be clearly indicated below
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..17: Bode plot
Code:
{Place your code here}
4.
Find the step response of the system in Figure Error! No text of specified
style in document..16 (Hint: use step (TF_BPF)), use the value of C, R, and L
in part c
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..18: Step Response
43
Code:
{Place your code here}
2.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
44
Experiment 5: Introduction to Simulink and Simulation of a Speed Control System
1.
Objectives
In this lab, we will introduce the basics of SIMULINK and how to build a control system, and
what are the main components. Then we will implement the system on MATLAB and learn
how to analyze it. In addition, we will learn the different functions of the basic blocks. We
will also learn how to make a dynamic model of a system using Simulink. In the end, we will
module an approximate simple first-order speed control system using Simulink.
The objectives can be summarized below:
1.
To introduce students to Simulink and be familiar with basic blocks.
2.
To familiarize the student with dynamic modeling using Simulink.
3.
To module an approximate simple first-order Speed Control System using Simulink.
4.
Theoretical Background
In addition to the simple background provided here, students are requested to read the
hand-out provided for MATLAB and MATLAB slides. Also, reviewing lecture slides. There is
also an external reference that you must read to understand the Speed Control system and
how-to module its dynamic system.
First of all, Simulink is a software developed to be used in many domains for simulation and
designing the dynamic system such as control systems. It belongs to MATLAB which works
side by side with the m-files to do many analyses and operations in the system. The most
important libraries that can be obtained in Simulink are Continues, Discreet, Math
Operation, User Defined Functions, and Generally Used Function.
5.
Simulink is software produce by MathWorks, Inc., for multi-domain simulation and
model-based design of dynamic and embedded systems.
6.
The block libraries offer various standard models for:
7.
1.
Communications
2.
Controls
3.
Signal/image/video processing systems
Two phases:
1.
Model building
2.
Model simulation/analysis
Secondly for a simplified model of a DC motor as in Figure Error! No text of specified style in
document..19, with zero losses due to hysteresis and voltage drop across the bruises, is
derived by writing the differential equation of the system and moving to the s-domain to
have the final result as shown:
Armature-controlled DC motor:
45
𝑊(𝑠)
𝑘𝑚
𝛼𝑚
=
=
𝑉𝑎(𝑠) (𝐿𝑎 𝑠 + 𝑅𝑎)(𝐽𝑠 + 𝑏) + 𝑘𝑚 𝑘𝑏 𝜏𝑚 𝑠 + 1
𝐽 𝑅𝑎
Equation Error! No
text of specified
style in document..3
𝑘𝑚
where 𝜏𝑚 = 𝑏 𝑅𝑎+𝑘𝑚 𝑘𝑏 , 𝛼𝑚 = 𝑏 𝑅𝑎+𝑘𝑚 𝑘𝑏
For the closed-loop speed control system
we have the following:
𝑊(𝑠) =
𝛼𝑚 𝑘𝑎 𝑘𝑡
𝜏𝑚 𝑠 + 1
𝑊𝑟(𝑠) −
𝐷(𝑠)
𝜏𝑚 𝑠 + 𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
𝜏𝑚 𝑠 + 𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
𝑒(𝑡) = 𝑤𝑟(𝑡) − 𝑤(𝑡)
𝐸(𝑠) = 𝑊𝑟(𝑠) − 𝑊(𝑠) =
𝜏𝑚 𝑆 + 1
(𝑊𝑟(𝑠) + 𝐷(𝑠))
𝜏𝑚 𝑠 + 𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
Equation Error! No
text of specified
style in document..4
Figure Error! No text of specified style in document..19: Electrical Diagram and Sketch of a
DC Motor [3]
8.
Experimental Apparatus
You need a computer with MATLAB software installed on it. Make sure Simulink package
working well to start working with simple building blocks for control systems.
9.
Experiment Work
46
1.
Using Simulink, design the simple sinusoidal block diagram and simulate it for 10
seconds as in Figure Error! No text of specified style in document..20.
Figure Error! No text of specified style in document..20: Sinusoidal Example
You need to define the initial condition of the integrator to zero.
1.
Double click on the scope to get the waveform and copy it to your report as in Figure
Error! No text of specified style in document..21. Comment on the three
waveforms?
{Place your Figure here}
Figure Error! No text of specified style in document..21
Comment on your result found in Figure Error! No text of specified style in document..21.
Ans:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2.
Build a Simulink model of the speed control system given in Figure Error! No text of
specified style in document..22.
𝑘𝑡 = 12 mV/(rad/sec),
𝜏𝑚 = 2.5 sec,
𝛼𝑚 = 10 (rad/sec)/V.
For the amplifier gain block: Ka = 10
Use a step reference speed of 100 rad/sec and a step disturbance input of 10 rad/sec, which
is applied 5 seconds later than the reference step. Add scopes to properly visualize the
simulation results. Also, use “To Workspace” blocks to send the time (generated by “Clock”)
and the shaft speed signals to the workspace. Save the file with a name.
47
Figure Error! No text of specified style in document..22: Part 1- Simple Speed Control
System with constant parameters
1.
Part 1: Double click on the scope to get the waveform and copy it to your report as
in Figure Error! No text of specified style in document..23. Then you need to
comment on the plot and explain the behavior of the system once the disturbance
occurred.
{Place your Figure here}
Figure Error! No text of specified style in document..23:
Comment on your result found in Figure Error! No text of specified style in document..23.
Ans:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2.
Part 2: copy the .slx file you have for the previous Simulink file and name it with a
different name. Then all the parameters’ values (as a constant number) on the block
should be redefined as a variable with the following names:
For the step input:
For the step disturbance:
Step time: t_in
Step time: t_d
Final value: in_f
Final value: d_f
48
For the gains: k_t, and k_a
For the Transfer
alpha_m, and tau_m
function
parameters:
Then you need to define these parameters’ values inside the m file on MATLAB. Next,
simulate the speed control system model and place your plot in Figure Error! No text of
specified style in document..24 and the MATLAB code. You have to show the title, legend,
x,y labels, and grid on the plot. Note, to change variable type for To Workspace block, look at
Figure Error! No text of specified style in document..25. Also, to output a single variable for
t and y, you need to change the simulation configuration as in Figure Error! No text of
specified style in document..26.
{Place your Figure here}
Figure Error! No text of specified style in document..24
Place below the code as a Reference
{ pace the code here for part 2 b }
Comment on your result found in Figure Error! No text of specified style in document..24.
Ans:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Change the variable type of the t and y to array type in the Simulink as below:
1.
For y
49
1.
For t
Figure Error! No text of specified style in document..25: Change variable types to an array
type
To export data to from Simulink to the MATLAB’s Workspace you need first to uncheck the
box in the below option as in Figure 4 below:
Figure Error! No text of specified style in document..26: Uncheck Single Simulation Output
2.
Part 3: Simulate the model and collect the time and shaft speed for three different
choices of “k_a”:
𝑘𝑎 1 = 10,
𝑘𝑎 2 = 20,
𝑘𝑎 3 = 50
Collect and plot the shaft speed signal versus time for these three different cases all in the
same plot of a single Figure. Use appropriate plot types, colors, labels, title, grid, and legends
to identify the curves. Adjust the time range, if necessary, to display the variations of the
speed visibly. Name the Simulink file with a different name. Then place the plot on your
report as in Figure Error! No text of specified style in document..27.
1.
Find and compare the theoretical and the experimental values of the steady-state
error:
50
Equation Error! No
text of specified
style in
document..5: [3]
𝜏𝑚 𝑆+1
𝐸(𝑠) = 𝑊𝑟(𝑠) − 𝑊(𝑠) = 𝜏𝑚 𝑠+𝛼𝑚 𝑘𝑎 𝑘𝑡+1 (𝑊𝑟(𝑠) + 𝐷(𝑠))
To find the stead-state error:
𝑒𝑠𝑠 = lim e(t)=lim 𝑤𝑟(𝑡) − 𝑤(𝑡) = lim 𝑊𝑟(𝑠) − 𝑊(𝑠) =
t→∞
t→∞
s→0
𝜏𝑚 𝑆 + 1
(𝑊𝑟(𝑠) + 𝐷(𝑠))
𝜏𝑚 𝑠 + 𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
1
110
=
∗ (100 + 10) =
𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
𝛼𝑚 𝑘𝑎 𝑘𝑡 + 1
Equation Error! No
text of specified
style in document..6
Then fill in Table Error! No text of specified style in document..22 below:
Table Error! No text of specified style in document..22: Stead-State speed and error
ka
Steady-State Shaft Speed [rad/sec]
Steady-State Error [rad/sec]
Theoretical
Experimental
…
………………
………………
………………
…
………………
………………
………………
…
………………
………………
………………
{Place your Figure here}
Figure Error! No text of specified style in document..27
Place below the code as a Reference
{ pace the code here for part 2 c }
Questions:
51
Q1: Does the steady-state error increase or decrease with increasing amplifier gain? Explain
and justify your observation based on theoretical expectations.
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Q2: Does the convergence time to steady-state increase or decrease with increasing
amplifier gain? Explain and justify your observation based on theoretical expectations.
Ans:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
52
Experiment 6: Simulation of a Prototypes Second Order System (Part 1)
1.
Objectives
In this experiment, we will use Simulink to design a second-order closed-loop system and
simulate it for few seconds. Also, we will analyze and describe the range of responses for the
second-order system when changing the values of damping ratios. Then we will use the basic
principle to calculate rising time, percent overshoot, peak time, and settling time for those
responses. In the second part of the experiment, we will use the second-order closed-loop
system and study the behavior of the system as we change the values of both natural
frequency and damping ratio.
The objectives can be summarized below:
2.
To module an approximated second order system using Simulink.
3.
To develop an improved understanding of second-order control systems.
4.
Use poles and zeros of transfer functions to determine the time response of a
control system.
5.
To know the general response of a second-order system given the pole location and
to find the settling time, peak time, percent overshoot, and rising time.
6.
Theoretical Background
Most dynamic systems are multi-order. However, learning a second-order system will be an
excellent start to the understanding of a higher-order system as they behave approximately in
the same manner. Also, there are numerous techniques used to approximate a higher-order
system to a second-order. A prototype second-order control system is shown in Figure Error!
No text of specified style in document..28.
Figure Error! No text of specified style in document..28: Prototype Second-Order ClosedLoop Control System
After reducing the feedback loop of the system of Figure Error! No text of specified style in
document..28 we will have the following:
𝑇(𝑠) =
𝑌(𝑠)
𝜔𝑛2
𝜔𝑛2
= 2
=
,
𝑅(𝑠) 𝑠 + 2𝜁𝜔𝑛 𝑠 + 𝜔𝑛2 (𝑠 + 𝑠1 )(𝑠 + 𝑠2 )
𝑤ℎ𝑒𝑟𝑒 𝑠1,2 = 𝜔𝑛 (𝜁 ∓ √𝜁 2 − 1 )
Equation
Error! No text
of specified
53
style in
document..7
The behavior of the second-order system can be described by well-known parameters
𝜁: Damping ratio.
𝜔𝑛 : (Undamped) Natural frequency.
Based on the value of the damping ratio, we can determine the behavior/type of response as
shown in Figure Error! No text of specified style in document..29.
Figure Error! No text of specified style in document..29: Response Type based on the
Damping Ratio Values ( 𝜻 ) [4]
1.
Over-Damped Case
We have over damp response if we have 𝜁 > 1 and the pole-zero map is indicated in Figure
Error! No text of specified style in document..30
Figure Error! No text of specified style in document..30: Pole-zero map location for OverDamped Case 𝜻 > 1
The output of a unit response can be described as in the below Equation Error! No text of
specified style in document..8.
𝑦(𝑡) = 1 −
𝜁 + √𝜁 2 − 1
2√𝜁 2 − 1
𝑒 −𝑆1 𝑡 +
𝜁 − √𝜁 2 − 1
2√𝜁 2 − 1
𝑒 −𝑆2 𝑡
Equation
Error! No text
of specified
style in
document..8
54
7.
8.
9.
In this case, the system has two distinct poles on the negative real axis.
Two exponentially decaying terms.
When the damping ratio is much larger than one, -s1 will be the dominant pole.
1.
Critically Damped Case
We have a critically damped response if we have 𝜁 = 1 and the pole-zero map is indicated in
55
Figure Error! No text of specified style in document..31: Pole-zero map location for
Critically-Damped Case ξ = 1
The system will have a double pole at −𝜔𝑛 as in Figure Error! No text of specified style
in document..31. The output of the unit response of the system can be found as in the
below Equation Error! No text of specified style in document..9:
𝑦(𝑡) = 1 − (1 + 𝜔𝑛 𝑡)𝑒 −𝜔𝑛𝑡
2.
Equation
Error! No text
of specified
style in
document..9
Under- Damped Case
We have an under-damped response if we have 0 < ζ < 1 and the pole-zero map is
indicated in Figure Error! No text of specified style in document..32.
Figure Error! No text of specified style in document..32: Pole-zero map location for UnderDamped Case 0 < 𝜻 < 1
56
The output of a unit response can be described as in the below Equation Error! No text of
specified style in document..8.
𝑦(𝑡) = 1 −
1 −𝜁𝜔 𝑡
𝑛 𝑠ⅈ𝑛(𝜔 𝛽𝑡 + 𝜃) , 𝑤ℎ𝑒𝑟𝑒 𝛽 = √1 − 𝜁 2 𝑎𝑛𝑑 𝜃
𝑒
𝑛
𝛽
= cos−1(𝜁)
10.
This response has two complex conjugate poles in the left half-plane.
11.
Damped sinusoidal response variation.
12.
The damping is determined by a decaying exponential envelope.
1.
Standard Performance Measures
Equation
Error! No text
of specified
style in
document..10
To quantify and study the behavior of a system superficially for an underdamped response
due to a step input, we will define rising time, peak time, settling time, and percentage
overshoot. Below Figure Error! No text of specified style in document..33 clearly shows
these performance parameters
Figure Error! No text of specified style in document..33: Performance Parameters Indication
in a Second-order underdamped response [2]
Some abbreviation and samples mentioned in Figure Error! No text of specified style in
document..33 explained below:
𝑇𝑟 , 𝑡𝑟 𝑜𝑟 𝜏𝑟 : rising time.
𝑇𝑝 , 𝑡𝑝 𝑜𝑟 𝜏𝑝 : peak time.
𝑇𝑠 , 𝑡𝑠 𝑜𝑟 𝜏𝑝 : settling time.
PO: percentage overshoot
57
C(t): the step-response of the system.
Cfinal: the final value of the response (or the steady-state final value, that is when the
response approach content value)
Cmax: the maximum value of the response
2.
Swiftness performance parameters:
1.
Rising Time
Rising time 𝜏𝑟 can be defined as the time it takes the output to rise from 10% to 90% of its
final steady-state value.
Below an approximate theoretical expression to measure the rising time.
𝜏𝑟 ≈
2.
2.16𝜁 + 0.6
, 0.3 ≤ 𝜁 ≤ 0.8
𝜔𝑛
Equation
Error! No text
of specified
style in
document..11
Peak Time
The time instant at which the output takes its maximum value.
You can find it theoretically by setting the first derivative of the output to zero and solve for
𝜏𝑟 and you will get the below theoretical result:
𝜏𝑝 =
3.
𝜋
𝑛
𝜔 √1 −
𝜁2
Equation
Error! No text
of specified
style in
document..12
The similarity to the step input performance parameters
1.
Percent Overshoot
It is an indicator of how much the peak value of the output exceeds its steady-state value. It
shows the ratio of the difference between the peak and steady-state values to the steadystate value.
Also, you can obtain that value theoretically as in Equation Error! No text of specified style
in document..13 below:
𝑃𝑂 =
−𝜋𝜁
(
)
2
√1−𝜁
100𝑒
Equation
Error! No text
of specified
style in
58
document..13
Expermintaly we can define PO as in below
𝑃𝑂 =
𝐶𝑚𝑎𝑥 − 𝐶𝑓𝑖𝑛𝑎𝑙
𝑃𝑒𝑎𝑘 𝑉𝑒𝑎𝑙𝑢𝑒 − 𝑆𝑡𝑒𝑎𝑑𝑦 𝑆𝑡𝑎𝑡𝑒 𝑉𝑎𝑙𝑢𝑒
Equation
× 100 =
× 100
Error! No text
𝑆𝑡𝑒𝑎𝑑𝑦 𝑆𝑡𝑎𝑡𝑒 𝑉𝑎𝑙𝑢𝑒
𝐶𝑓𝑖𝑛𝑎𝑙
of specified
style in
document..14
2.
Setting Time
It is the time required for the output to settle within usually 2% or 5% of the input
amplitude. Theoretically, it is estimated to be four times the time constant of the system as
in eq. below:
𝜋≈
2.
4
≈ 4𝜏,
𝜁𝜔𝑛
𝑤ℎ𝑒𝑟𝑒 𝜏 =
1
𝜁𝜔𝑛
Equation
Error! No text
of specified
style in
document..15
Un-Damped Case
We have an un-damped response if we have ξ = 0 and the pole-zero map is indicated in
Figure Error! No text of specified style in document..34.
59
Figure Error! No text of specified style in document..34: Pole-zero map location for UnDamped Case
The system has two complex conjugate poles on the imaginary axis. The output of a unit
response can be described as in the below Equation Error! No text of specified style in
document..16.
𝑦(𝑡) = 1 − 𝑐𝑜𝑠(𝜔𝑛 𝑡)
Equation
Error! No text
of specified
style in
document..16
The response is a pure cosine wave shifted by a const of one unit. As the poles still in the
imaginary axis and never go to the positive real axis it will be considered marginally stable.
Which is a behavior between unstable and stable.
A summary of the four responses of the system as we change the damping ratio ζ is clearly
shown in Figure Error! No text of specified style in document..35 below:
Figure Error! No text of specified style in document..35: Step Response of second-order
system for different Damping Cases [2]
60
4.
Experimental Apparatus
You need a computer with MATLAB software installed on it. Make sure the Simulink package
working well to start working with simple building blocks for control systems and to build a
second-order system.
1.
Remarks for using Simulink
To change the step size in your Simulink simulation follow the numbered step in Figure
Error! No text of specified style in document..36 below:
Figure Error! No text of specified style in document..36: Changing the Step Size in Simulink
To find the raising time in MATLAB for the response, you need to use min( ) function as in
Figure Error! No text of specified style in document..37 below:
Figure Error! No text of specified style in document..37: Illustration to Find the Raising Time
in MATLAB using min( ) Function
61
62
5.
Experiment Work
1.
Simulate a second-order system with a natural frequency of 𝝎𝒏 = 1.5 rad/sec, and a
damping ratio of 𝜻 =1/3. Set the simulation time to t_fin=20 seconds. Then plot the
output response due to a step input of a final value of 1 with a step time at 0 (that is
the transition time start at time zero) [plot using MATLAB, so you need to export the
output to workspace then you will use plot commend, legend, title, x,y, label and
grid].
Figure Error! No text of specified style in document..38: A Prototype Second-Order Closed Loop Control System Using Simulink
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..39: The Block diagram of the secondorder system from Simulink
{Place your Figure here}
Figure Error! No text of specified style in document..40: Single Step Response for a SecondOrder System with ω_n=1.5 rad/sec, and to 𝜻 = 𝟏/𝟑
1.
Change the damping ratio to 𝜻 =1 and plot the response for ω_n=1.5 rad/sec and
its poles-zero map. Then place them in Figure Error! No text of specified style in
document..41 and Figure Error! No text of specified style in document..42
respectively.
{Place your Figure here}
63
Figure Error! No text of specified style in document..41: Single Step Response for a SecondOrder System with ω_n=1.5 rad/sec, and to 𝜻 = 𝟏
{Place your Figure here}
Figure Error! No text of specified style in document..42: Pole-zero map, ω_n=1.5 rad/sec and
𝜻 =1
2.
Change the damping ratio to 𝜻 =2 and plot the response for ω_n=1.5 rad/sec and
its poles-zero map. Then place them in Figure Error! No text of specified style in
document..43 and Figure Error! No text of specified style in document..44
respectively.
{Place your Figure here}
Figure Error! No text of specified style in document..43: Single Step Response for a SecondOrder System with ω_n=1.5 rad/sec, and to 𝜻 = 𝟐
{Place your Figure here}
Figure Error! No text of specified style in document..44: Pole-zero map, ω_n=1.5 rad/sec
and 𝜻 =2
3.
Change the damping ratio to 𝜻 =0.5540 and 𝝎𝒏 = 13.8767 and plot the and its
poles-zero map. Then place them in Figure Error! No text of specified style in
document..45 and Figure Error! No text of specified style in document..46
respectively. Then fill the Table Error! No text of specified style in document..23
only for this case (part c).
64
{Place your Figure here}
Figure Error! No text of specified style in document..45: Single Step Response for a SecondOrder System with ω_n=13.8767 rad/sec, and to 𝜻 = 𝟎. 𝟓𝟓𝟒𝟎
{Place your Figure here}
Figure Error! No text of specified style in document..46: Pole-zero map, 𝜻 =0.5540 and wn
= 13.8767
Table Error! No text of specified style in document..23: Finding Performance parameter of
the second-order system for the last case of 𝜻 =0.5540 and wn = 13.8767
The maximum value
(Overshot)
Experimental
---------
Experimental
---------
Theory
---------
Peak Time (Tp)
Steady-State (final value)
--------Experimental
---------
Theory
---------
Experimental
---------
Theory
---------
Theory
---------
Rise time (Tr)
Percent overshoot (PO)
Settling time (Ts)
4.
Comment on the result you get from parts a,b and c. Also, indicate the type of
damping based on the value of the damping ratio.
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------65
5.
Simulate a second-order system with different values of damping ratio (𝜻), ZETA=
[0, 0.2, 0.5, 0.7, 1.0, 2.0, 5.0] for two cases of natural frequency (𝝎𝒏). In the first
case, a natural frequency of wn=1.5 rad/sec and in the second case a natural
frequency of wn=2.5 rad/sec, that is for WN=[1.5, 2.5]. You should plot the step
response of the system of all values of zetas in one plot of a single figure for the first
case of wn=1.5 rad/sec and the second figure of all the value of zeta in case of
wn=2.5 rad/sec. Note: you need to include title, legend, x,y label, and grid.
Ans:
{Place your Figure here}
Figure Error! No text of specified style in document..47: for wn=1.5
{Place your Figure here}
Figure Error! No text of specified style in document..48: for wn=2.5
Questions 1: Explain the changes observed in the unit step response in response to an
increase in 𝜻 and 𝝎𝒏 ?
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------6.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
66
Experiment 7: Simulation of a Prototypes Second Order System (Part 2)
1.
Objectives
In this experiment, we will continue our study in the prototype second-order system with
the help of Simulink, and MATLAB software. This part will focus on studying the effect of the
damping ratio 𝜁 on the percentage of overshoot and rising time. Then we will test the effect
of adding zeros and poles in the system and see how it behaves by looking at its
performance parameters.
The objectives can be summarized below:
1.
To study the effect of the damping ratio 𝜁on the percentage of overshoot and
rising time.
2.
2.
test the effect of adding zeros and poles in the system and see how it behaves
by looking at its performance parameters.
Theoretical Background
Students are requested to read the theoretical background provided in the previous
experiment (Experiment 0, page 53). Also, to look at lecture slides to review some concepts.
3.
Experimental Apparatus
You need a computer with MATLAB software installed on it. Make sure the Simulink package
working well to start working with simple building blocks for control systems and to build a
second-order system.
4.
Experiment Work
Use the Simulink file developed earlier in experiment number 0 for the second-order system
and then follow the instruction below:
5.
Write a MATLAB m-file to determine the percent overshoot and the 10-to-90 % rise
time from the step responses with wn = 1.5 and 𝜻 = 0 to 1 in the step of 0.05. Plot
the experimental and theoretical results versus zeta in the same figure. Identify the
curves clearly with title, legend, x,y labels, and grid. Indicate your theoretical result
with red line and a “+” marker. Whereas your experimental results with blue line
and “o” marker. Your x-label should be named with zeta latter like this “𝜻”.
Ans:
{Place your Figure here}
67
Figure Error! No text of specified style in document..49: Percent overshoot, (PO Vs. 𝜻).
{Place your Figure here}
Figure Error! No text of specified style in document..50: Rise time, (Tr Vs. 𝜻)
Question 1: Which one of PO and rise time shows much difference from the values obtained
from its analytical expression? What is your explanation for this observation?
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------6.
Modify your Simulink model to obtain and plot the unit step response when we add
zero or pole and place your results in Figure Error! No text of specified style in
document..52 and Figure Error! No text of specified style in document..53
respectively as follow:
1.
Adding a zero to the transfer function with parameter B=[1/0.4, 1/0.8, 1/1, 1/3,
1/5, 1/10, 0]
Figure Error! No text of specified style in document..51: Adding zero to the transfer
function
{Place your Figure here}
Figure Error! No text of specified style in document..52: Adding a zero
68
2.
Adding a pole to the transfer function with a parameter B=[1/0.4, 1/0.8, 1/1, 1/3,
1/5, 1/10, 0]
Figure Error! No text of specified style in document..53: Adding pole to the transfer
function
{Place your Figure here}
Figure Error! No text of specified style in document..54: Adding a pole
Question 2: Explain the changes observed in the percent overshoot and the settling time in
response to a change in the additional zero and pole location.
Ans:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------3.
Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
69
Experiment 8: Study PID Controller on a Simple Mechanical System
1.
Objectives
In this experiment, we will be able to control the values of proportional, integral, and
derivative gains and study their impact on the transient and steady-state performance of a
control system. Dynamic performance characterization focuses on overshoot, steady-state
error, rise time, and settling time. Once the effects of individual gains are established, we
will vary the controller’s configurations (P, PD, PI, and PID) and eventually design an optimal
PID controller by means of fine and tuning the gains’ parameters.
The objectives can be summarized below:
1.
To learn the fundamental concepts of designing a PID controller based closedloop system.
2.
2.
To learn how to model, design, simulate and implement a complete feedback
control system by using Simulink.
3.
To design various controller configurations (P, PD, PI, and PID) and investigate
the effects of proportional, integral, and derivative gains on system performance
including steady-state error, percent overshoot, rise time, settling time, and
system stability.
Theoretical Background
One common controller is a PID controller. It is basically a combination of promotional,
integral, and derivative controller summed together after the error signal in the block
diagram of a control system as in Figure Error! No text of specified style in document..55
and Figure Error! No text of specified style in document..56. Because most engineering
understands the basic principle of proportional, derivative, and integral, one can use this
controller without a deep understanding of control theory [5].
Figure Error! No text of specified style in document..55: Basic Block Diagram of a Control
system with General Controller indicated with C(s) [5].
70
Figure Error! No text of specified style in document..56: PID Controller components in a
feedback Control system [6].
From Figure Error! No text of specified style in document..55 and Figure Error! No text of
specified style in document..56 we can see that the PID controller composes of proportional
action, integral action, and derivative action. The set-point/reference signal r or the input
signal will be compared (taking the difference) with the output signal. This error signal will
be the input to the PID controller. We can express the time domain output 𝒖(𝒕) of the PID
controller as in Figure Error! No text of specified style in document..56 in term of the error
signal as in Equation Error! No text of specified style in document..17 below [5]:
𝑢(𝑡) = 𝑘𝑝 𝑒(𝑡) + 𝑘𝑖 ∫ 𝑒(𝑡) 𝑑𝑡 + 𝑘𝑑
𝑑𝑒
𝑑𝑡
Equation
Error! No text
of specified
style in
document..17
So, after taking the Laplace transfer of Equation Error! No text of specified style in
document..17, we can express the transfer function of our PID controller as in eq below:
𝑇𝐹(𝑠) =
𝑘𝑑 𝑠 2 + 𝑘𝑝 𝑠 + 𝑘𝑖
𝑈(𝑠)
𝑘𝑖
= 𝑘𝑝 + + 𝑘𝑑 𝑠 =
𝐸(𝑠)
𝑠
𝑠
Equation
Error! No text
of specified
style in
document..18
Where:
𝑘𝑝 : is the proportional gain.
𝑘𝑖 : is the integral gain.
𝑘𝑑 : is the derivative gain.
The proportional gain kp will increase the strength of the error signal. Which cause the
system to react faster (reducing the raising time 𝑡𝑟 ) and also will reduce the stead-sate error
but it cannot make it zero. The issue with a proportional gain is the increase of overshoot of
the response.
Adding a derivative action with kd gain will provide anticipation of the error [5]. Because the
derivative is the rate of change of the response, the control signal will be larger as the error
going upward. This prediction will enable the system to correct itself in a way similar to
introducing damping in the system to reduce its overshoot behavior. It also, help the system
71
to settle faster (that is reducing the settling time ts). However, a small change can be
observed in the rising time.
Adding integral action with ki gain will help the system to eliminate the steady-state error.
The nature of integral is the accumulation of previous error singles that persist in the
response and continue appearing [5]. This means the controller will have a history of the
error signal, which helps the controller to hunt it down. However, the integral action will
introduce oscillation behavior as the error signal keeps changing sign. So, the system will
take more time to settle and also increase the overshoot of the system. On the other hand,
the rising time will decrease and have a faster response.
The summary of the effect of each controller action on the closed-loop system’s
performance parameters is clearly shown in Table Error! No text of specified style in
document..24 below:
Table Error! No text of specified style in document..24: Summary of the Effect of Each Gain
of PID Controller on a Close-loop System’s Performance parameters
3.
CL RESPONSE
RISE TIME
OVERSHOOT
SETTLING
TIME
S-S
ERROR
Kp
Decrease
Increase
Small Change
Decrease
Ki
Decrease
Increase
Increase
Decrease
Kd
Small
Change
Decrease
Decrease
No Change
Experimental Apparatus
You need a computer with MATLAB software installed on it. Make sure the Simulink package
working well.
1.
Remarks for using Simulink
To show time-axis label on the scope, double click on the scope then click on the gear at
the top menu (configuration properties). Then follow the steps in Figure Error! No text
of specified style in document..57 below.
Figure Error! No text of specified style in document..57: Placing Time-Axis Label on the
Waveform of a Scope in Simulink
72
To show the y-label on the scope, click on the Display tab of the configuration properties as
in Figure Error! No text of specified style in document..58 below. Then write in front of the
Y-label the name you want for your y-axis.
Figure Error! No text of specified style in document..58: Placing Y-axis label on the
Waveform of a Scope in Simulink
4.
Experiment Work
In experiment number 0 (MATLAB/Simulink tutorials in modeling dynamic systems (Part 1)).
We explore the effect of changing a physical system's parameters and observe its impulse
response. Now we will take one of the simplest mechanical systems and implement a
different configuration of PID controller in open-loop and closed-loop systems. So, let us
consider the mass-spring-damper system as in Figure Error! No text of specified style in
document..59
Figure Error! No text of specified style in document..59: Mass-Spring-Damper System to
Study PID Controller
The transfer function considers the force F(t) as the input and the displacement X(t) as the
output for the system as in Equation Error! No text of specified style in document..19 below:
𝑥(𝑠)
1
=
2
𝑓(𝑠) 𝑚𝑠 + 𝑏𝑠 + 𝑘
Equation
Error! No text
73
of specified
style in
document..19
Let consider the physical design of the system’s parameters as in Table Error! No text of
specified style in document..25 below:
Table Error! No text of specified style in document..25: Mass-Spring-Damper Physical
Design Parameters
Symbol
Definition
Value
Unit
m
Mass of the object
1
𝑘𝑔
b
Damper viscosity
friction constant
10
𝑁⋅𝑠∕𝑚
k
Spring constant
20
𝑁⁄
𝑚
The input to the system will be a unity, that is a force of 1 Neaton ( F = 1 N).
The controller problem here is to design the controller’s parameters (kp, ki, and kd) such that
we will have a minimum rising time, minimum overshoot, and zero steady-state error
(this is the design criteria).
For that let us investigate the effect of each controller parameter in the system in the
following five cases below:
74
1.
Open-Loop Step Response
Let's first view the open-loop step response. Build the block diagram of the system using as in
Figure Error! No text of specified style in document..60 using Simulink and MATLAB.
Change the simulation time accordingly (let’s say from t=0 to t=3 seconds or to t=10
seconds). Adjust the x-label, y-label, and grid on the scope (look at Figure Error! No text of
specified style in document..57 and Figure Error! No text of specified style in
document..58). Also, increase the data point by changing the step size of the simulation as
we did in previous experiments (let’s say 0.01 for the step size). Then find the waveform of
the step-response of the system and place it in Figure Error! No text of specified style in
document..61. Lastly, find the performance parameters as in Table Error! No text of
specified style in document..26 below by using courses measurement in the scope
(Simulink). Then verify your results using stepinfo(y,t) built-in function in MATLAB (where
y is a vector representing the step-response of your system and t is a vector representing the
time in seconds). Then answer Q1.
Figure Error! No text of specified style in document..60: Open-Loop System (without
controller)
{Place your Figure here}
Figure Error! No text of specified style in document..61: Open Loop Step Response (without
controller), (from Scope or MATLAB plot)
Table Error! No text of specified style in document..26: Performace Parameters for the
Open-Loop System (without controller)
Performance Paramters
Value
DC gain of the plant transfer function
………..………..
(final value of the step response)
Steady-state error
………..………..
75
Percentage Overshot
………..………..
Rising Time
………..………..
Settling Time
………..………..
Q1: For the above open-loop system in Figure Error! No text of specified style in
document..61 comment on the steady-state error, and the rising time? And how will you plan
to improve it?
Ans: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2.
Close-Loop Step Response with Proportional Controler
Now we will add a proportional controller (which is a gain just after the error signal in the
block diagram) and unity feedback (which could be a proximity sensor to detect the location
of the object). Set the proportional gain to kp=300, then build the block diagram of the system
using Simulink and .m file in MATLAB as in Figure Error! No text of specified style in
document..62 below. Change the simulation time accordingly (let’s say from t=0 to t=2
seconds). Adjust the x-label, y-label, and grid on the scope (look at Figure Error! No text of
specified style in document..57 and Figure Error! No text of specified style in
document..58). Also, increase the data point by changing the step size of the simulation as
we did in previous experiments (let’s say 0.01 for the step size). Then find the waveform of
the step-response of the system and place it in Figure Error! No text of specified style in
document..63. Lastly, find the performance parameters as in Table Error! No text of
specified style in document..27 below by using courses measurement in the scope
(Simulink). Then verify your results using stepinfo(y,t) built-in function in MATLAB (where
y is a vector representing the step-response of your system and t is a vector representing the
time in seconds). Then answer Q2.
Figure Error! No text of specified style in document..62: Close-Loop System with
Proportaionl Controller (kp)
76
{Place your Figure here}
Figure Error! No text of specified style in document..63: Close-Loop System Response with
Proportional Controller (kp)
Table Error! No text of specified style in document..27: Performace Parameters for CloseLoop System with Proportaionl Controller (kp)
Performance Paramters
Value
DC gain of the plant transfer function
………..………..
(final value of the step response)
Steady-state error
………..………..
Percentage Overshot
………..………..
Rising Time
………..………..
Settling Time
………..………..
Q2: For the closed-loop system with a proportional controller in Figure Error! No text of
specified style in document..63, what is the effect of the proportional controller in the system
in terms of steady-state error, percentage overshoot, rising time, and settling time
(elaborate/or comment)?
Ans: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------3.
Closed-Loop Step Response with Proportional-Derivative Controler
Now we will add a derivative controller. So, we will have a Proportional and derivative action
in our design. Set the proportional gain to kp=300 and derivative gain to kd = 10, then build
the block diagram of the system using Simulink and .m file in MATLAB as in Figure Error!
No text of specified style in document..62 below. Change the simulation time accordingly
(let’s say from t=0 to t=2 seconds). Adjust the x-label, y-label, and grid on the scope (look at
Figure Error! No text of specified style in document..57 and Figure Error! No text of
specified style in document..58). Also, increase the data point by changing the step size of
the simulation as we did in previous experiments (let’s say 0.01 for the step size). Then find
the waveform of the step-response of the system and place it in Figure Error! No text of
specified style in document..65. Lastly, find the performance parameters as in Table Error!
No text of specified style in document..28 below by using courses measurement in the scope
(Simulink). Then verify your results using stepinfo(y,t) built-in function in MATLAB (where
y is a vector representing the step-response of your system and t is a vector representing the
time in seconds). Then answer Q3.
77
Figure Error! No text of specified style in document..64: Close-Loop System with Proportional and
Derivative Controller (kp + kd*s)
{Place your Figure here}
Figure Error! No text of specified style in document..65: Close-Loop System Response with
Poportoinal and Derivative Controller (Kp +Kd*s)
Table Error! No text of specified style in document..28: Performace Parameters for CloseLoop System with Proportional and Derivative Controller (kp + kd*s)
Performance Paramters
Value
DC gain of the plant transfer function
………..………..
(final value of the step response)
Steady-state error
………..………..
Percentage Overshot
………..………..
Rising Time
………..………..
Settling Time
………..………..
Q3: For the closed-loop system with a proportional and derivative controller in Figure Error!
No text of specified style in document..65, what is the effect of adding the derivative
controller in the system in terms of steady-state error, percentage overshoot, rising time, and
settling time (elaborate/or comment)?
Ans: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------4.
Close-Loop Step Response with Proportional-Integral Controler
78
Now we will add an integral controller. So, we will have a Proportional and integral action in
our design. Set the proportional gain to kp=30 and integral gain to ki = 70, then build the
block diagram of the system using Simulink and .m file in MATLAB as in Figure Error! No
text of specified style in document..66 below. Change the simulation time accordingly (let’s
say from t=0 to t=4 seconds). Adjust the x-label, y-label, and grid on the scope (look at Figure
Error! No text of specified style in document..57 and Figure Error! No text of specified style
in document..58). Also, increase the data point by changing the step size of the simulation as
we did in previous experiments (let’s say 0.01 for the step size). Then find the waveform of
the step-response of the system and place it in Figure Error! No text of specified style in
document..67. Lastly, find the performance parameters as in Table Error! No text of
specified style in document..29 below by using courses measurement in the scope
(Simulink). Then verify your results using stepinfo(y,t) built-in function in MATLAB (where
y is a vector representing the step-response of your system and t is a vector representing the
time in seconds). Then answer Q4.
Figure Error! No text of specified style in document..66: Close-Loop System with
Proportional and Integral Controller (kp + ki*1/s)
{Place your Figure here}
Figure Error! No text of specified style in document..67: Close-Loop System Response with
Proportional and Integral Controller
(kp + ki *1/s)
Table Error! No text of specified style in document..29: Performace Parameters for CloseLoop System with Proportional and Integral Controller (kp + ki*1/s)
Performance Paramters
Value
DC gain of the plant transfer function
………..………..
(final value of the step response)
Steady-state error
………..………..
79
Percentage Overshot
………..………..
Rising Time
………..………..
Settling Time
………..………..
Q4: For the closed-loop system with a proportional and integral controller in Figure Error! No
text of specified style in document..67, what is the effect of adding the integral controller in
the system in terms of steady-state error, percentage overshoot, rising time, and settling time
(elaborate/or comment)?
Ans: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------5.
Close-Loop Step Response with Proportional-Integral-Derivative
Controler
Finally, we will have a Proportional, integral, and derivative action in our design. Set the
proportional gain to kp=350, the integral gain to ki = 300, and the derivative gain to kd=50,
then build the block diagram of the system using Simulink and .m file in MATLAB as in
Figure Error! No text of specified style in document..68 below. Change the simulation time
accordingly (let’s say from t=0 to t=4 seconds). Adjust the x-label, y-label, and grid on the
scope (look at Figure Error! No text of specified style in document..57 and Figure Error! No
text of specified style in document..58). Also, increase the data point by changing the step
size of the simulation as we did in previous experiments (let’s say 0.01 for the step size).
Then find the waveform of the step-response of the system and place it in Figure Error! No
text of specified style in document..69. Lastly, find the performance parameters as in Table
Error! No text of specified style in document..30 below by using courses measurement in the
scope (Simulink). Then verify your results using stepinfo(y,t) built-in function in MATLAB
(where y is a vector representing the step-response of your system and t is a vector
representing the time in seconds). Then answer Q5.
Figure Error! No text of specified style in document..68: Close-Loop System with
Proportional, Integral and Derivative Controller (kp+ki*1/s+kd*s)
{Place your Figure here}
80
Figure Error! No text of specified style in document..69: Close-Loop System Response with
Proportional, Integral and Derivative Controller (kp + ki *1/s + kd*s)
Table Error! No text of specified style in document..30: Performace Parameters for CloseLoop System with Proportional, Integral, and Derivative Controller (kp + ki*1/s+kd*s)
Performance Paramters
Value
DC gain of the plant transfer function
………..………..
(final value of the step response)
Steady-state error
………..………..
Percentage Overshot
………..………..
Rising Time
………..………..
Settling Time
………..………..
Q4: For the close-loop system with proportional, integral, and derivative controller in Figure
Error! No text of specified style in document..69, what is the effect of pro[portaionl, integral,
and derivative as a whole in the system in term of steady-state error, percentage overshoot,
rising time, and settling time (elaborate/or comment)?
Ans: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------6.
Summary of the Performance Parameters for Different PID
configurations
Collect all your findings of performance parameters for Table Error! No text of specified
style in document..26, Table Error! No text of specified style in document..27, Table Error!
No text of specified style in document..28, Table Error! No text of specified style in
document..29, and Table Error! No text of specified style in document..30, then place them
in Table Error! No text of specified style in document..31. Then comment on Table Error!
No text of specified style in document..31 by answering question Q6 below.
Table Error! No text of specified style in document..31: Summary of Performace Parameters
for the five PID configurations
Performance
Paramters
Open Loop
System (no
Controller)
Close-Loop
System with
Proportional
Controller
(kp)
DC gain of the
plant transfer ………..………..
function (final
value of the step
………..………..
Close-Loop
System with
Proportional,
Integral and
Derivative
Controller
Close-Loop
System with
Proportional
and Derivative
Controller
Close-Loop
System with
Proportional
and Integral
Controller
(kp + kd*s)
(kp + ki *1/s)
(kp + ki *1/s +
kd*s)
………..………..
………..………..
………..………..
81
response)
steady-state
error
………..………..
………..………..
………..………..
………..………..
………..………..
Percentage
Overshot
………..………..
………..………..
………..………..
………..………..
………..………..
Rising Time
………..………..
………..………..
………..………..
………..………..
………..………..
Settling Time
………..………..
………..………..
………..………..
………..………..
………..………..
Q5: Comment generally on your summarized table above by comparing the different
configurations (advantages and disadvantages for each case)? Also, which one is the most
suitable design based on the design criteria mentioned at the beginning (minimum rising
time, minimum overshoot, and zero steady-state error)?
Ans: -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------[fyi]: General Tips for Designing a PID Controller [5]
When you are designing a PID controller for a given system, follow the steps shown below to
obtain the desired response. [5]
1.
Obtain an open-loop response and determine what needs to be improved [5]
2.
Add a proportional control to improve the rise time [5]
3.
Add a derivative control to reduce the overshoot [5]
4.
Add an integral control to reduce the steady-state error [5]
5.
Adjust each of the gains kd, ki, and kd until you obtain a desired overall response. You
can always refer to Table Error! No text of specified style in document..24 shown in the
Theoretical Background page 72 in this
When you design a PID controller, it is not necessary to use all controller actions
(proportional, derivative, and integral) [5]. Instead, tray as possible to make your design
simple if you find PD or PI or even just P is sufficient to your design requirement, then you
can carry ahead with your design.
5. Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
Experiment 9: Design Feedback Controllers using Root Locus Technique for a Specific
Performance Parameter
1.
Objectives
In this experiment, we design a control system using a root locus. To find the root locus of an
open-loop system is by finding all possible proportional gain Kp of a closed-loop system as kp
82
goes from 0 to infinity. That is, we observe the poles and zero movements in the pole-zero map
as we keep changing the proportional gain of the close loop system of that plant.
We use MATLAB rlocus commend for a transfer function to find the rout-locus. Then we use
sgrid(zeta,wn) commend to find the possible range of design for the specific design
parameter. Then we find the proportional control gain and its corresponding poles with the
help of [k,poles] = rlocfind( ) command in MATLAB. To test the validity of the design we test
the system using step input after finding the close loop transfer function of the system with
unity feedback and a kp equal to the obtained value from rlofind() commend.
The objectives can be summarized below:
2.
To introduce students to root locus and how to plot it using MATLAB.
3.
To design a feedback controller for a specific performance criterion using root locus.
4.
To introduce students to the root locus tools used in MATLAB.
5.
Theoretical Background
One old technique to analyze system relative stability and transient performance of a closedloop system based on the location of the close-lop roots of a characteristic equation in the polezero map (s-plane), is called root locus [7]. Let us consider the closed-loop system win unity
feedback and proportional gain parameter in Figure Error! No text of specified style in
document..70.
Figure Error! No text of specified style in document..70: Close-Loop System with Unity
Feedback, and Proportional Gain Parameter to study Root Locus Technic
After reducing the block diagram to find the close-loop transfer function, we will have Equation
Error! No text of specified style in document..20 below:
𝑌(𝑠)
𝑘𝐺(𝑠)
𝑝(𝑠)
=
=
,
𝑅(𝑠) 1 + 𝑘𝐺(𝑠) 𝑞(𝑠)
𝑤ℎ𝑒𝑟𝑒 𝐺(𝑠) =
𝑏(𝑠)
𝑎(𝑠)
Equation
Error! No text
of specified
style in
document..20
Where k is a variable parameter takes the following values 0 ≤ 𝑘 ≤ ∞ and p(s), q(s), b(s), and
a(s) are polynomials in s. The closed-loop characteristic equation is 1 + 𝑘𝐺(𝑠) = 0 will represent
the poles of the system in the s-plane.
We can express the characteristic equation of a closed-loop in terms of its open-loop numerator
and denominator, that is b(s) and a(s) respectively as in Equation Error! No text of specified
style in document..21 below:
83
𝑌(𝑠)
=
𝑅(𝑠)
𝑏(𝑠)
𝑝(𝑠)
𝑏(𝑠)
𝑎(𝑠)
=
, ⅈ𝑡𝑠 𝑝𝑜𝑙𝑒𝑠 ⅈ𝑠 𝑤ℎ𝑒𝑛 𝑞(𝑠) = 1 + 𝑘
=0
𝑏(𝑠) 𝑞(𝑠)
𝑎(𝑠)
1+𝑘
𝑎(𝑠)
𝑘
𝑞(𝑠) = 1 + 𝑘
𝑏(𝑠)
= 0 ⟹ 𝑎(𝑠) + 𝑘𝑏(𝑠) = 0
𝑎(𝑠)
𝑎(𝑠)
+ 𝑏(𝑠) = 0,
𝑘
Equation
Error! No text
of specified
style in
document..21
𝑤ℎ𝑒𝑟𝑒 𝑏(𝑠) 𝑛𝑢𝑚𝑟𝑎𝑡𝑜𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑜𝑝𝑒𝑛 𝑙𝑜𝑜𝑝 𝑠𝑦𝑠𝑡𝑒𝑚 𝑎𝑛𝑑 𝑎(𝑠) ⅈ𝑡𝑠 𝑑𝑒𝑛𝑜𝑚ⅈ𝑛𝑎𝑡𝑜𝑟
To find the poles of the closed-loop system we take the limit of 𝑘 → 0 and its poles will poles of
the open-loop system G(s), or the solution of the polynomial a(s) = 0. However, if we take the
limit as 𝑘 → ∞, then we will get another pole for a closed-loop system that is the zeros of the
open-loop system G(s), which is the solution of the polynomial b(s) = 0 [5].
Rool locus helps us to find the stability of the system as we have all possible locations of poles of
a closed-loop system as we change K. Not that only, but also can be useful to design a system
with specific criteria (like certain rising time, settling time, percentage overshoot, etc… ) that will
guarantee a certain performance.
Below a summary of a typical open-loop transfer function, int its corresponding closed-loop root
locus map.
Table Error! No text of specified style in document..32: Root Locus Plots for Typical Transfer
Functions G(s) [7]
Open-Loop
Open-Loop
Root Locus
# Transfer Function
Root Locus
# Transfer Function
(on the s-plane)
(on the s-plane)
G(s)
G(s)
1
2
3
4
84
5
6
Table Error! No text of specified style in document..32 (Continued): Root Locus Plots for
Typical Transfer Functions G(s) [7]
Open-Loop
Open-Loop
Root Locus
#
Transfer Function
Root Locus
#
Transfer Function
(on the s-plane)
(on the s-plane)
G(s)
G(s)
7
8
9
10
11
12
13
14
85
15
6.
Experimental Apparatus
You need a computer with MATLAB software installed on it. Make sure the Simulink package
working well.
7.
Experiment Work
Consider an open-loop system with a transfer function as in eq below:
𝐺(𝑠) =
𝑌(𝑠)
𝑠+7
=
𝑈(𝑆) 𝑠(𝑠 + 5)(𝑠 + 15)(𝑠 + 20)
Equation
Error! No text
of specified
style in
document..22
You are asked to use the root locks technique to design a closed-loop system with a controller
k that has the following design criteria:
8.
A percentage overshoot less than 5%.
9.
A rising time less than 1 second.
So, you need first to use a .m file in MATLAB and write your transfer function of the openloop system by defining the complex variable s like this: s = tf(‘s’), then write the transfer
function in terms of the defined complex variable s like this: sys =
(s+7)/(s*s(s+5)(s+15)*(s+20)). Then you can find the root locus by simply using the
command rlocus(sys), where sys is your defined transfer function in your .m file. To display
part of the plot (by zooming in or out) you can use xlim([a,b]) and ylim([c,d]), or you can
change both axes at the same time using axis([a,b,c,d]). Place your plot in Fig. below:
{Place your Figure here}
Figure Error! No text of specified style in document..71: Root Locus Plot for a System
To find the acceptable range of the root locus that will satisfy the design criteria above, we
can simply use the command sgrid(zeta,wn). The two arguments are zeta for the damping
ratio (could be a vector or constant) and wn for the natural frequency (also could be a vector
or constant). For our design criteria, we can obtain mathematically the corresponding zeta
and wn values from the percentage overshoot and the rasing time.
86
10.
A percentage overshoot less than 5% (PO < 0.05) → means a damping ratio 𝜁 > 0.7
11.
A rising time less than 1 second (tr < 1) → means a natral frequency wn > 1.8
So, you can write in .m file the following lines:
zeta = 0.7;
wn=1.8;
sgrid(zeta,wn)
Then place your plot in Figure Error! No text of specified style in document..72 below:
{Place your Figure here}
Figure Error! No text of specified style in document..72: Root Locus Plot for a System with
Range of Acceptable Desing Indicated in Doted Lines
The two doted straight 45-degree from the x-axis lines are the location of poles where zeta
𝜁 = 0.7. In between those lines 𝜁 > 0.7 and outside those lines 𝜁 < 0.7. So, we should select
poles that are between (and including) those dotted lines (𝜁 > 0.7). The damping ratio is
proportional to the cosine angle of the dotted line with respect to the x-axis (that is 𝜁 =
𝑐𝑜𝑠(𝜃)). The natural frequency will be 𝜔𝑛 = 1.8 for poles on the dotted semicircle, 𝜔𝑛 < 1.8
for poles insdie the semicirciule and 𝜔𝑛 > 1.8 for poles outside the semicircle. So, the proper
design should be outside the semicircle to satisfy 𝜔𝑛 > 1.8 condition [5].
So, as a designer, you will select the root from the root locus map that satisfies this boundary
condition mentioned above. In MATLAB there is a command that will enable you to chose
with your mouse on the s-plan the desirable pole that is within this boundary condition. This
commend is [k, pole] = rlocfind(sys), where the two-argument output of this rlocfind( )
function are “k” for the proportional gain of your controller, and the “pole” is all poles of the
open-loop system. Then left-click on those selected poles which are close to the imaginary yaxis to show their coordinate values on the plot and place your figure in Figure Error! No text
of specified style in document..73 below:
{Place your Figure here}
Figure Error! No text of specified style in document..73: Root Locus Plot for a System with
Selected Poles for Satisfying the Desing Criteria
87
To verify your design, you need to test the system with a step input. However, you need first
to find the closed-loop transfer function by simply using the MATLAB command
feedback(FF,FB). Where FF stands for Feedforward polynomial of the complex number s
and FB stand for the Feedback polynomial of the complex number s. in our case we have a
FF = k*sys for the feedforward and a unity (that is FB=1) for the feedback. So, in your .m
file write the following lines:
k= 350; % use the k value you got after you select the pole in Figure Error! No text of
specified style in document..73
FF = k*sys;
FB = 1;
sys_cl= feedback(FF,FB);
After you get your closed-loop transfer function sys_cl from the above line, you can now test
using step(sys_cl) commend to see if your response within less than 5% of PO and less than 1
second of rising time. Then place your response in Figure Error! No text of specified style in
document..74 below:
{Place your Figure here}
Figure Error! No text of specified style in document..74: Root Locus Plot for a System with
Selected Poles for Satisfying the Desing Criteria
A better way to design a controller with the root locus technique is to use the interactive
Control System Designer tool within the control toolbox of MATLAB. This tool is used to
analyze and design for the system and to improve the step response [5]. To access this tool
you need just to write the rltool(sys) in your .m file (or command window), where sys is the
open-loop transfer function of your system.
5. Observations and/or Conclusions: {List all pertinent observations and/or
conclusions}
88
APPENDIX A: ABET Student Outcome 6 Assessment Rubric
ABET Student Outcome 6: An ability to develop and conduct appropriate experimentation, analyze and interpret data, and use engineering judgment to draw conclusions
Performance Indicator Beginning/Minimal (1)
Developing (2)
Proficient (3)
Exemplary (4)
Score
Conduct experimentation Missing objective
Weak or unclear objective
Adequate objective
Objective is appropriately narrow
Missing functional description Weak description of experimental Adequate description of
and focused
of experimental apparatus
apparatus
experimental apparatus
Full description of experimental
Missing identification of key Poor identification of key data
Adequate identification of key
apparatus and identification of all
data collection parameters
collection parameters
data collection parameters
relevant variables
Missing experimental data
Data collection procedure is
Data collection procedure is
Data collection procedure is detailed
collection procedure.
formulated poorly.
formulated adequately but missing without being unnecessarily
details.
complicated.
Acquire data on
Data acquisition appears to
Data acquisition does not include
Data acquisition includes most
Data acquisition includes all
appropriate variables
have significant errors or
any detail on instrument precision or instrument capabilities (sensitivity relevant sensitivity and calibration
unrealistic accuracy (fake or accuracy performance
& calibration)
information
made-up data?)
(sensitivity & calibration)
Data acquisition setup is
Data acquisition setup is carefully
Data collected for variables
Acquired data is not accompanied illustrated / explained, but a few and thoroughly explained
that are not part of experiment by a data acquisition illustration or minor details are missing
Input data covers entire range of
plan or some variables are not diagram (test setup not
Input data covers most of the
interest, as well as some additional
sampled
adequately described)
“range of interest” for the key
points / configurations that might be
Missing large portions of data Input data range is significantly
variables.
of interest without wasting time on
range.
limited or obviously meaningless for
unnecessary procedures.
some variables.
Interpret experimental data No comparison made, or
Weak comparison of data to
Adequate comparison made to
Thorough comparison conducted
and results with respect to comparison made to irrelevant appropriate model
appropriate model
between sufficiently varied data set
appropriate theoretical
models.
Comparison of data made to model Model includes important
and detailed model
models
that doesn’t include some important relationships among key variables, Theoretical model is sufficiently
relationships
though
detailed to provide insight into
among key variables.
some minor details are missing. Driving Question.
Explain observed
Differences are not identified Most differences are correctly
All major differences are
All relevant differences have been
differences between model or are incorrectly explained
identified, but many are poorly
identified; only a few minor
identified
and experiment (bad
Neither the possibility of using explained
differences have been ignored
Potential weaknesses in both model
model, bad measurements, the wrong model nor of
Explanation of differences does not Both model and data have been and data collection procedure have
noise, etc.) and draw
collecting erroneous data has consider use of wrong model or
explored as possible sources of
been identified, but both are well
conclusions
been identified
possibility of having erroneous data error
done
Conclusions are not justified. Conclusions are weakly justified.
Conclusions are partially justified Conclusions are fully justified by
by analysis.
rigorous analysis.
89
APPENDIX B: Mechanical and Electrical Laws for Deriving Dynamic Module
Translational Mechanical Components [2]
Table Error! No text of specified style in document..33: Dynamic Module for Translational Mechanical
Components [2]
Rotational Mechanical Components [2]
Table Error! No text of specified style in document..34: Dynamic Module for Rotational Mechanical
Components [2]
Electrical Components [2]
Analogy with mechanical system:
12.
Spring == Capacitor
13.
Viscous Damper == Resistor
14.
Inductor == Mass/inertia
90
Table Error! No text of specified style in document..35: Dynamic Module for Electrical Components [2]
APPENDIX C: Creating Multiple Curves in One Plot using For Loop
Here is an example of how to create multiple curves in one plot by changing a parameter of the y axis inside a
for-loop as in the example of a sine wave with different frequencies in Figure Error! No text of specified style
in document..75 below.
f = [1 0.5 2];
t=0:0.001:10;
for n=1:length(f)
y=sin(f(n)*t);
figure(1)
plot(t,y)
hold on;
Namef(n)={['f='
num2str(f(n))]};
Figure Error! No text of specified style in document..75:
Example of Multiple Curves in One plot using For Loop
end
legend(Namef)
grid on;
xlabel('Time')
ylabel('Amp')
title('Differnet Sine Freq')
91
92
APPENDIX D: MATLAB Basic and Control Systems Commands
1.
Basic MATLAB Commands
Table Error! No text of specified style in document..36: Basic MATLAB Commands
#
Command
Usage
Example
1
help
It will provide you wthe nessary
>> help sin
information of any command in MATLAB
sin Sine of argument in radians.
or related topics to that
command/function and will display the
sin(X) is the sine of the elements of X.
help text in the Command Window.
See also asin, sind, sinpi.
Reference page for sin
Other functions named sin
2
clc
Clear command window.
3
clear all
removes all variables, globals, functions
and MEX links.
4
close all
closes all the open figure windows.
5
close(F)
Closes figure F
6
whos
returns a structure with the fields:
name, size, bytes, etc…
7
ans
Variable store the last result of your
command window execution.
2*3
ans =
6
8
( ), ^, *, /, +, -
The basic mathematical operations and %{
parentheses. The priority of operation
Write and calculate the mathematical
can be summarized in this word
expression below:
“PEMDAS”:
2 × 102 − 0.57
P: parentheses
2.5
25
E: exponential
%}
M: multiplication
D: division
A: addition
S: subtraction
(2*10^-2-0.57)/2^5^2.5
%{
ans =
-9.4948e-05
93
%{
% However it is a good practice to use
% parentheses as much as you can to
make it
% simple to read, even if the priority is
met.
(2*10^-2-0.57)/(2^5^2.5)
%{
ans =
-9.4948e-05
%{
3-2^4
(3*2)^4
3-2^4
8/2^4
2^4\8
9
i
j
Reserved word/letter for complex
number ⅈ = √−1 and 𝑗 = √−1 .
i
%{
ans =
0.0000 + 1.0000i
%{
10 a1 = [1 2 3]
a2 = [1, 2, 3]
Creating a 1x3 (row) vector in two
different ways.
a1= [1 2 3]
a2 = [1, 2, 3]
%{
a=
1
2
3
2
3
a2 =
1
%}
11 b1 = [1
2
Creating a 3x1 (column) vector in two
different ways.
b1 = [1
2
94
3]
3]
b2 = [1; 2; 3]
b2 = [1; 2; 3]
%{
b1 =
1
2
3
b2 =
1
2
3
%}
12 A = [33, 21; 41, 10]
Creating a 2x2 matrix
A = [33, 21; 41, 10]
%{
A=
33 21
41 10
%}
13 A(2) = 5
Accessing the 1-D indexing to the second A = [33, 21; 41, 10]
element counting from the first column
A(2) = 5
going down. Then changing its content
to a value of 5.
%{
A=
33 21
5 10
%}
14 a + b
if we add two vectors/matrixes we need a = [2 3 4]
to have a matching size. The adding will
b= [6 8 7]
be an element by element addition.
a+b
%{
ans =
8 11 11
95
%}
15 a – b
if we subtract two vectors/matrixes we a = [2 3 4]
need to have a matching size. The
b= [6 8 7]
addition will be an element by element
manner.
a -b
%{
ans =
-4 -5 -3
%}
16 a.*b
if we elementwise multiply two
a = [2 3 4]
vectors/matrixes we need to have a
b= [6 8 7]
matching size. The multiplication will be
an element by element manner.
a .*b
%{
ans =
12 24 28
%}
17 a./b
Element by elment division
a = [2 3 4]
b= [6 8 7]
a ./b
%{
ans =
0.3333 0.3750 0.5714
%}
18 a^n
a^2
Normal/matrix power of a, or rising the a=[2 3; 5 8]
matrix a to the power n or 2.
a^2
Note: here we need to consider the
%{
condition of matrix multiplication, which
is the number of columns of the first
matrix should equal the number of rows
of the second matrix.
ans =
19 30
50 79
%}
96
19 a.^n
a.^2
Elementwise power of a.
a=[2 3; 5 8]
a.^2
%{
ans =
4
9
25 64
%}
20 a'
Transpose of a vector/matrix (only if it is a=[2 3; 5 8]
not a complex number). However, if it is
a’
a complex number then it will be a
transpose of a conjugate of that
%{
complex number.
ans =
2
5
3
8
%}
a=[3+6i 2-8i]
A= a'
%{
ans =
3.0000 - 6.0000i
2.0000 + 8.0000i
%}
21 a.'
Transpose of a vector/matrix
a=[3+6i 2-8i]
A= a.'
%{
ans =
3.0000 + 6.0000i
2.0000 - 8.0000i
%}
22 a = 4:10
The colon generates a sequence of
numbers from 4 to 10 with a default
increment of 1.
a = 4:10
%{
a=
97
4
5
6
7
8
9
10
%}
23 a = 4:2:10
a=4:2:9
The colon generates a sequence of
a = 4:2:10
numbers from 4 to 10 with an increment
%{
of 2.
a=
4
6
8 10
%}
a=4:2:9
%{
a=
4
6
8
%}
24 a = 10:-1:4
The colon generates a sequence of
numbers from 10 to 4 with a decrement
of 1.
25 linespace(a,b,n)
Generates linearly spaced vectors
linspace(2,10,5)
starting by a end by b and has n element
%{
a: staring point, b: ending point,
ans =
n: number of elements
2 4 6 8 10
%}
26 x(:)
Taking all the elements of R and stacking x= [2 3 ;7 8 ; 2 44 ]
all the columns one after the other in a
x(:)
one-column vector.
%{
x=
2
3
7
8
2 44
ans =
98
2
7
2
3
8
44
%}
27 R(n:end)
All the elements from nth to the last
element.
28 R(2:5)
All the elements from 2nd to the 5th
element of R
R= [2 3 5 70;7 8 10 40; 2 44 90 79]
R(2:5)
%{
ans =
7
2
3
8
%}
29 R(3,1)
Accessing the element located in the 3rd R= [2 3 5 70;7 8 10 40; 2 44 90 79]
row and 1st column.
R(3,1)
%{
ans =
7
2
3
8
%}
30 R(n,:)
All the elements of the row number n.
(all n row elements)
31 R(:,n)
All the elements of the column number
n. (all n column elements)
32 diag(R)
All the diagonal elements of R
33 R(2,2:4)
The elements of row 2 from column
number 2 to column number 4
R= [2 3 5 70;7 8 10 40; 2 44 90 79]
R(2,2:4)
%{
ans =
99
8 10 40
%}
34 end
represents the last index of an array.
B=[5 7 1 8 3;
9 6 4 2 5 ];
B(1,2:end)
means: select the elements from the
second column to the last column of
the first row in a matrix B
35 [ ]
:
36 length(R)
Using an empty square bracket and
B(3,:) = [ ];
colon can delete a certain row or column
means: delete the third row of matrix
in a matrix.
B, or in other words fix row 3 and move
to all columns to delete those
elements.
Length of largest array dimension in R
length(R)
ans = 4
37 size(R)
size(R,1)
size(R,2)
38 find(condition)
Size of array R. Where the output is a
vector of two elements. The first
element represents the number of rows
and the second one represents the
number of columns. size(R,1) gives the
number of rows only. size(R,2) gives the
number of columns only.
size(R)
Return a column of 1D indices of
elemnts those satisfying the input
condition
X=[ 1
0
2;
0
1
1;
0
0
4]
%{
ans =
3 4
%}
> find(X)
ans =
1
5
7
8
9
x=-8:0.1:8;
y=(-(x).^2+10);
100
plot(x,y)
a=find(y>=max(y))
39 [r c] = find()
Returns 2D indices of elements that
satisfy the input condition
[r c] = find(X)
a=
r: column vector contains row’s numbers
1
c: column vector contains column’s
numbers
2
1
2
3
b=
1
2
3
3
3
40 [A, B]
Concatenates horizontally
41 [A; B]
Concatenates vertically
42 char1='hello world this is
Mohammed'
Creating a character vector with the
name char1. The size of this vector is 1 x
28.
43 char2='Ahmed'
Creating a character vector with the
name char2. The size of this vector is 1 x
5.
45 str1="hello world this is
Mohammed"
Creating a scaler string with the name
str1. The size of this vector is 1 x 1.
46 str2="Ahmed"
Creating a scaler string with the name
str2. The size of this vector is 1 x 1.
str2="Ahmed"
%{
str2 =
101
"Ahmed"
%}
47 str3=["Ahmed",”Omar”]
Creating a vector string with the name
str3.
str3=["Ahmed",”Omar”]
%{
str3 =
1×2 string array
"Ahmed" "Omar"
%}
48 num2str(num1)
“converts a numeric array into a
character array that represents the
numbers” [1]
Usually used for title and legend.
num1=90
NS1=num2str(num1)
%{
num1 =
90
NS1 =
'90'
%}
char7=['I got ',NS1,' in my final exam of
dynamic course out of 100']
49 x=Input(‘Enter
Something’)
“displays the text in prompt and waits
for the user to input a value and press
the Return key” [1]
prompt = 'Enter a Number: ';
x = input(prompt)
y = x*10
50 plot( x,y )
2-D line plot
x,y : could be any variable
plotting x Vs. y
51 xlabel(‘Text’)
x = 0: 0.01:2*pi;
y = sin(x);
plot(x,y)
Label x-axis
xlabel(‘Angle in Radeon’)
Label y-axis
ylabel(‘Amplitude’)
Text: could be any text or
string
52 ylabel(‘Text’)
Text: could be any text or
102
string
53 legend(‘Text’)
Add legend to axes
legend('cos(x)','cos(2x)')
Add a title to the figure
title(‘Sine Vs its Angle in Radeon’)
Create a figure with index n window.
figure(1)
Note: it is useful when you create
multiple plots in a supported window
like in the example
x = 0: 0.01:2*pi;
Text: could be any text or
string
54 title(‘Text’)
Text: could be any text or
string
55 figure (n)
y1 = sin(x);
plot(x,y1)
figure(2)
x = 0: 0.01:2*pi;
y2 = cos(x);
plot(x,y2)
56 grid on
Display axes grid lines
57 subplot(m,n,p)
divides the current figure into an m-by-n x = 0:0.1:2*pi;
grid and creates axes in the position
y1=sin(x);
specified by p
y2=sin(2*x);
m, n, p : can be changed
y3=sin(4*x);
subplot(2,2,1)
plot(x,y1,'--')
xlabel('t')
ylabel('Amplitude')
title('y1')
grid on
subplot(2,2,2)
plot(x,y2,':')
103
xlabel('t')
ylabel('Amplitude')
title('y2')
grid on
subplot(2,2,[3 4])
plot(x,y3,':')
xlabel('t')
ylabel('Amplitude')
title('y3')
grid on
58 xlim([a b])
specifies the x-axis limits for the current
axes. Where a is the lower limit and b is
the upper limit of the x-axis [1].
59 ylim([c d])
specifies the y-axis limits for the current
axes. Where c is the lower limit and d is
the upper lmit of the y-axis [1].
60 axis([a b c d])
sets scaling for the x- and y-axes on the
current plot [1].
2.
Keyboard shortcuts in MATLAB
Table Error! No text of specified style in document..37: Keyboard shortcuts in MATLAB
#
Keyboard’s key
Usage
1
F1
After you highlight the command in the MATLAB .m file or command window, you will
get Help/documentation about the command.
2
F5
To run the whole .m code from the beginning till the end line.
3
F9
To through the highlighted lines of codes.
4
F10
Run code line
5
F11
Run code line, enter functions
6
Ctrl + c
Force the code to be stoped. (interrupts code)
7
Ctrl + r/t
Comment/uncomment line(s)
3.
Basic MATLAB Commands for Control System
104
Table Error! No text of specified style in document..38: Basic MATLA Commands for Control System
#
Command
Usage
Example
1
roots(p)
Polynomial roots: returns the roots of % p(s) = 𝑠 3 − 5𝑠 2 − 2
the polynomial represented by p as a
p=[1 -5 0 -2];
column vector.
r=roots(p)
%result:
r = 5.0776 + 0.0000i
-0.0388 + 0.6264i
-0.0388 - 0.6264i
% p(s) = 𝑠 3 + 12𝑠 2 + 32𝑠
roots([1 12 32 0])
ans=
0
-8
-4
2
[r,p,k] = residue(b,a)
finds the residues, poles, and direct num=[32];
term of a Partial Fraction Expansion of
den=[1 12 32 0];
the ratio of two polynomials. [8]
[r, p, k]=residue(num,den)
% results:
r=
1
-2
1
p=
-8
-4
0
k=
[]
105
3
[b,a] = residue(r,p,k)
converts the partial fraction expansion [b,a] = residue(r,p,k)
back to the ratio of two polynomials
%result:
and returns the coefficients in b and a.
[8]
b=
0
0 32
a=
1 12 32
4
ilaplace(F)
0
returns the Inverse Laplace Transform syms s
of F. By default, the independent
ys=32/(s^3+12*s^2+32*s)
variable is s and the transformation
variable is t. If F does not contain s, yt=ilaplace(ys)
ilaplace uses the function symvar
%results:
ys =
32/(s^3 + 12*s^2 + 32*s)
yt =
exp(-8*t) - 2*exp(-4*t) + 1
5
linespace(a,b,n)
Generates linearly spaced vectors
starting from a, till b and has n
element
linspace(2,10,5)
ans = 2
4
6
8 10
a: staring point, b: ending point,
n: number of elements
6
inv(A)
The inverse of a matrix A
A = [1 2;3 4];
inv(A)
ans =
-2.0000 1.0000
1.5000 -0.5000
7
[T,D] = eig(A)
“produces a diagonal matrix D of
eigenvalues and
a full matrix V whose columns are
the corresponding eigenvectors
so that A*V = V*D”. [1]
A = [1 2;3 4];
[T,D] = eig(A)
%{
results:
T=
-0.8246 -0.4160
106
0.5658 -0.9094
D=
-0.3723
0
0 5.3723
%}
8
sys=tf(N,D)
creates a continuous-time transfer
function sys with numerator N and
denominator D [1].
N = [1 1];
D = [1 1 4];
sys = tf(N,D);
%{
Results:
sys =
s+1
----------s^2 + s + 4
%}
9
s=tf('s')
Defining a complex number s as an
s=tf('s')
object to be used in an expression to
sys = (s+1)/(s^2+s+4)
build a transfer function like a normal
mathematical expression.
%{
Results:
sys =
s+1
----------s^2 + s + 4
%}
10 pole(sys)
To find the poles of the transfer
function sys.
s=tf('s')
sys = (s+1)/(s^2+s+4)
pole(sys)
%{
Results:
ans =
-0.5000 + 1.9365i
107
-0.5000 - 1.9365i
%}
11 zero(sys)
To find the zeros of the transfer
function sys.
s=tf('s')
sys = (s+1)/(s^2+s+4)
zero(sys)
%{
Results:
ans =
-1
%}
12 [p,z]=pzmap(sys)
“returns the poles and zeros of the
s=tf('s')
system in two column vectors P and Z.
sys = (s+1)/(s^2+s+4)
No plot is drawn on the screen” [1].
[p,z]=pzmap(sys)
%{
Results:
p=
-0.5000 + 1.9365i
-0.5000 - 1.9365i
z=
-1
%}
13 pzmap(sys)
To drawa the pole-zero map in the
s=tf('s')
complex plan (s-plane). Where poles
sys = (s+1)/(s^2+s+4)
are plotted with x’s and zeros are
polotted with o’s [1].
pzmap(sys)
%{
Results:
108
%}
14 impulse(sys)
To plot the impulse response of the
dynamic system sys [1].
s=tf('s')
sys = (s+1)/(s^2+s+4)
impulse (sys)
%{
Results:
%}
15 step(sys)
To plot the step response of the
dynamic system sys [1].
s=tf('s')
sys = (s+1)/(s^2+s+4)
step(sys)
%{
Results:
%}
109
16 bode(sys)
To plot the bode frequency response s=tf('s')
of the dynamic system [1].
sys = (s+1)/(s^2+s+4)
bode(sys)
%{
Some hints used in change options:
Results:
opts = bodeoptions
opts.MagUnits = ‘abs’
opts.FreqUnits = ‘Hz’
bode( )
%}
17 nyquist(sys)
To plot the Nyquist frequency
response of the dynamic system sys
[1].
18 sys1 + sys2
parallel(sys1,sys2)
The parallel combination of two
s=tf(‘s’);
transfer functions is the same as if we
sys1=(s+2)/(s^2+2*s+3);
add them.
sys2=(s+3)/(s^2-4*s+1);
sys1 + sys2
parallel(sys1,sys2)
%{
Results:
ans =
2 s^3 + 3 s^2 + 2 s + 11
-----------------------------s^4 - 2 s^3 - 4 s^2 - 10 s + 3
ans =
2 s^3 + 3 s^2 + 2 s + 11
-----------------------------s^4 - 2 s^3 - 4 s^2 - 10 s + 3
%}
110
19 sys1 * sys2
series(sys1,sys2)
The series combination of two
s=tf(‘s’);
transfer functions is the same as if we
sys1=(s+2)/(s^2+2*s+3);
multiplay them [1].
sys2=(s+3)/(s^2-4*s+1);
sys1 * sys2
series(sys1,sys2)
%{
Results:
ans =
s^2 + 5 s + 6
-----------------------------s^4 - 2 s^3 - 4 s^2 - 10 s + 3
ans =
s^2 + 5 s + 6
-----------------------------s^4 - 2 s^3 - 4 s^2 - 10 s + 3
%}
20
sys1/(1+sys1*sys2)
feedback(sys1,sys2)
To find the feedback of two transfer s=tf(‘s’);
function in a control system. The first
sys1=(s+2)/(s^2+2*s+3);
aragument of feedback() function is
the feedforward branch and the
sys2=(s+3)/(s^2-4*s+1);
second argument is the feedback
branch. The feedback() function will sys1/(1+sys1*sys2)
reduce the transfer function to its lost feedback(sys1,sys2)Results:
term as it will cncle the common poles
%{
and zeros. Whereas the first
expression will not [3].
Results:
ans =
s^5 - 8 s^3 - 18 s^2 - 17 s + 6
---------------------------------------s^6 - 4 s^4 - 17 s^3 - 10 s^2 + 3 s + 27
ans =
s^3 - 2 s^2 - 7 s + 2
----------------------------111
s^4 - 2 s^3 - 3 s^2 - 5 s + 9
%}
21 minreal(sys1/(1+sys1*sys2)) Minimal realization and pole-zero
cancellation [1].
s=tf(‘s’);
sys1=(s+2)/(s^2+2*s+3);
sys2=(s+3)/(s^2-4*s+1);
minreal (sys1/(1+sys1*sys2))
%{
Results:
ans =
s^3 - 2 s^2 - 7 s + 2
----------------------------s^4 - 2 s^3 - 3 s^2 - 5 s + 9
%}
22 open('modelname');
Open the Simulink file with the name
modelname.
Note: the .m file should be in the
same location as the Simulink file to
open it.
23 sim('modelname');
Simulate the Simulink file with the
name modelname.
Note: the .m file should be in the
same location as the Simulink file to
simulate it.
24 stepinfo(y,t)
s = stepinfo(Y,T,YFINAL)
Computes step response
characteristics, where y is the output
response of the system and t is the
time of simulation in seconds [1].
“ takes step response data (T,Y) and a
steady-state value YFINAL and
returns a structure S containing
the following performance
indicators:
* RiseTime: rise time
* SettlingTime: settling time
112
* SettlingMin: min value of Y once
the response has risen
* SettlingMax: max value of Y once
the response has risen
* Overshoot: percentage
overshoot (relative to YFINAL)
* Undershoot: percentage
undershoot
* Peak: peak absolute value of Y
* PeakTime: time at which this
peak is reached. “ [1].
25 rlocus(sys)
To find the root locus map of the
system sys.
s=tf('s')
sys = (s+1)/(s^2+s+4)
rlocus(sys)
%(
Results:
%}
26 sgrid(zeta ,wn)
“generates a grid over an existing
s=tf('s')
continuous s-plane root locus or polesys = (s+1)/(s^2+s+4)
zero map. Lines of constant damping
ratio (zeta) and natural frequency
rlocus(sys)
(Wn) are drawn” [1].
sgrid(0.5,1.3)
%(
Results:
113
%}
27 rlocfind(sys)
“is used for interactive gain selection
from the root locus plot of the SISO
system SYS generated by RLOCUS.
rlocfind puts up a crosshair cursor in
the graphics window which is used to
select a pole location on an existing
root locus. The root locus gain
associated with this point is
returned in K and all the system poles
for this gain are returned in POLES.”
[1]
s=tf('s')
sys = (s+1)/(s^2+s+4)
rlocus(sys)
sgrid(0.5,1.3)
rlocfind(sys)
%(
Results:
%}
28 rltool(sys)
“ opens the SISO Design Tool with
s=tf('s')
Root Locus view on. Using this GUI,
sys = (s+1)/(s^2+s+4)
you can interactively design a singleinput/single-output (SISO)
rltool(sys)%(
compensator using the Root Locus
Results:
technique. ” [1]
“rltool(PLANT) further specifies the
plant model PLANT to be used in the
SISO Tool.” [1]
%}
4.
Codes/Commands Used for Dynamic Modeling
Table Error! No text of specified style in document..39: Codes/Commands Used for Dynamic Modeling
#
Commant
Usage
Example
1
ss(A,B,C,D)
create state-space models (ss model
objects) with real- or complex-valued
A= [-4 -1.5; 4 0];
114
matrices or to convert dynamic system B=[2; 0];
models to state-space model form.
C=[1.5 0.625];
D=0;
system_ss=ss(A,B,C,D)
subplot(2,1,1)
step(system_ss)
subplot(2,1,2)
impulse(system_ss)
2
[num, den]=ss2tf(A,B,C,D)
*converts a state-space representation A= [-4 -1.5; 4 0];
of a system into an equivalent transfer
[num, den]=ss2tf(A,B,C,D,ni)
B=[2; 0]; % one input
function.
C=[1.5 0.625];
D=0;
* returns the transfer function that
results when the nth input of a system [num, den]=ss2tf(A,B,C,D)
with multiple inputs is excited by a unit
%{
impulse.
Results:
num: numerator of the transfer
function
num =
den: denominator of the transfer
function
den =
0
1
3
5
4
6
A: System matrix [n x n]
%}
B: Input matrix [n x m]
C: Output matrix [p x n]
D: Feedforward matrix [p x m]
ni: number of inputs [m]
[n]: index dimension for state variables
A=[0 -1; 1 -2];
B = [1 -3; 2 4];
C = [1 -2; 2 3];
D=[0 0; 0 0];
[m]: index dimension for the input
[p]: index dimension of output
for n=1:size(B,2)
[num, den]=ss2tf(A,B,C,D,n)
end
%{
Results:
num =
115
0 -3.0000 -2.0000
0 8.0000 3.0000
den =
1.0000 2.0000 1.0000
num =
0 -11.0000 -4.0000
0 6.0000 -29.0000
den =
1.0000 2.0000 1.0000
%}
3
tf(ss(A,B,C,D))
Converting a state-space
representation of a system into a
transfer function.
A= [-4 -1.5; 4 0];
B=[2; 0]; % one input
C=[1.5 0.625];
D=0;
system_ss=ss(A,B,C,D)
system_tf=tf(system_ss)
%{
Results:
system_tf =
3s+5
------------s^2 + 4 s + 6
%}
4
syms
%{
With the help of
inv()
Converting a state-space
syms s
representation of a system into a
A= [-4 -1.5; 4 0];
transfer function using a mathematical
formulation with the help of symbolic B=[2; 0]; % one input
expression.
C=[1.5 0.625];
D=0;
116
eye()
GS=C*inv(s*eye(size(A))-A)*B
size()
%{
%}
Results:
GS =
(3*s)/(s^2 + 4*s + 6) + 5/(s^2 + 4*s + 6)
%}
5.
Special Characters
Table Error! No text of specified style in document..40: Special Characters used in MATLAB [9]
#
The character
Name/Usage
Example
1
.
Period or dot
102.5543
* Decimal point
A.*B
* Element-wise operations
A.^2
Comma
A = [12,13; 14,15]
* Separator
A(1,2)
Use commas to separate row elements in an
array, array subscripts, function input, and
output arguments, and commands entered on
the same line.
plot(x,y)
Colon
x = 1:10
* Vector creation
x = 1:2:30
* Indexing
Index a range of elements in a
particular dimension:
2
3
,
:
* For-loop iteration
A(2:5,3)
Index all elements in a
particular dimension:
A(:,3)
x = 1;
for k = 1:25
x = x + x^2;
end
117
4
;
Semicolon
A = 12.5; B = 42.7, C = 1.25;
* Suppress output of code line
Result:
* Signify end of row
B=
42.7000
A = [12,13; 14,15]
5
()
Parentheses
(A.*(B./C)) - D
* Operator precedence
plot(X,Y,'r*')
* Function argument enclosure
A(1,2)
* Indexing
6
[]
Square brackets
X = [10 12 -3]
* Array construction
A = rand(3);
* Array concatenation
A = [A; 10 20 30]
* Empty matrix and array *element deletion
A = []
* Multiple output argument *assignment
A(:,1) = []
[C,iA,iB] = union(A,B)
7
{}
Curly brackets
myCell = {1, 2, [8 0 6];
* “Use curly braces to construct a cell array, or to
'text', rand(5,10,2), {11;
access the contents of a particular cell in a cell 22; 33}}
array” [9].
%{
Results:
118
myCell =
*” Index to a specific cell array element by enclosing
all indices in curly braces “ [9].
2×3 cell array
{[ 1]} {[
double}
2]} {1×3
{'text'} {5×10×2 double}
{3×1 cell }
%}
myCell{5}
myCell{1,3}
%{
ans =
8
0
6
%{
myCell(1,3)
%{
ans =
1×1 cell array
{1×3 double}
%}
8
%
Percent
% The purpose of this loop is to
compute
* Comment: nonexecutable text within the body
of a program.
% the value of ...
9
%%
* Code Sections
%% This section of the code
performs the addition of ...
%% The second section will ….
10 %{ %}
Percent curly bracket
%{
* Block comments: comments that extend
beyond one line.
The purpose of this routine is
to compute
the value of ...
%}
119
11 ''
Single quotes
chr = 'Hello, world'
* Character array constructor: Use single quotes
to create character vectors that have class char.
12 ""
Double quote
S = "Hello, world"
* String constructor: Use double quotes to create
string scalars that have a class string.
13 N/A
Space character
A = [12 13; 14 15]
* Separator: Use the space character to separate [Y I] = max(A)
row elements in an array constructor, or the
values returned by a function. In these contexts, [Y,I] = max(A)
the space character and comma are equivalent. Both are the same
14 ~
15 =
Tilde
A = eye(3);
* Logical NOT
~A
Equal sign
A = [1 0; -1 0];
* Assignment
B = A;
B(1) = 200;
6.
Arithmetic Operators
Table Error! No text of specified style in document..41: Arithmetic Operators [9]
#
Operator
Usage
1
+
* Addition , * Unary plus
2
-
* Subtraction, *Unary plus
3
.*
* Element-wise multiplication
4
*
* Matrix multiplication
5
./
* Element-wise right division
6
/
* Matrix right division
7
.\
* Element-wise left division
8
\
* Matrix left division
9
.^
* Element-wise power
10
^
* Matrix power
11
.'
* Transpose
12
'
* Complex conjugate transpose
120
7.
Relational Operators
Table Error! No text of specified style in document..42: Relational Operators
#
Operator
Usage
1
==
Equal to
2
~=
Not equal to
3
>
Greater than
4
>=
Greater than or equal to
5
<
Less than
6
<=
Less than or equal to
8.
Logical Operators
Table Error! No text of specified style in document..43: Logical Operators [9]
#
Operator
Usage
1
&
Logical AND
2
|
Logical OR
3
&&
Logical AND (with short-circuiting)
4
||
Logical OR (with short-circuiting)
5
~
Logical NOT
9.
Basic Mathematical Functions
Table Error! No text of specified style in document..44: Basic Mathematical Functions [8]
#
Command
Usage
Example
1
sin(x)
Sine of argument in radians
x = 0:0.01:2*pi;
y = sin(x);
2
sind(x)
Sine of argument in degrees
x = 0:0.5:360;
y = sind(x);
3
cos(x)
Cosine of argument in radians
4
cosd(x)
Cosine of argument in degrees
5
tan(x)
Tangent of argument in radians
6
tand(x)
Tangent of argument in degrees
7
log10(x)
Common logarithm (base 10)
Log10(1000)
121
ans = 3
8
log(x)
Natural logarithm
log(2.718281828459)
ans = 1
9
exp(x)
returns the exponential ex for each element in array x.
exp(1)
ans = 2.71828
10
sqrt(x)
returns the square root of each element of the array x
sqrt(16)
ans = 4
11
abs(x)
* returns the absolute value of each element in array x.
abs(-7)
* If x is complex, abs(x) returns the complex magnitude. ans = 7
abs(3 + 4i)
ans = 5
12
real(x)
Returns the real part of a complex number
real(3+4i)
ans = 3
13
imag(x)
Returns the imagery part of a complex number
imag(3 + 4i)
ans = 4
14
min(x)
Returns the minimum value of a vector x
min([50 -70 100])
ans = -70
15
max(x)
Returns the maximum value of a vector x
max([50 -70 100])
ans = 100
16
sum(x)
Returns the summation of all vector’s elements
sum([40 10 5])
ans = 55
17
round(x)
Round x to the nearest integer
round([2.4 -2.4 2.5 -2.5 2.6 -2.6])
ans = 2 -2
18
ceil(x)
Round x toward positive infinity
floor(x)
Round toward negative infinity
3 -2
3 -2
floor([2.4 -2.4 2.5 -2.5 2.6 -2.6])
ans= 2 -3
10.
3 -3
ceil([2.4 -2.4 2.5 -2.5 2.6 -2.6])
ans = 3 -2
19
3 -3
2 -3
2 -3
Functions used to Build Matrices
Table Error! No text of specified style in document..45: Functions used to Build Matrices [8]
#
Commant
Usage
Example
122
1
eye(m,n)
Identity matrix
eye(3,3)
* Returns an m-by-n matrix with 1’s on the diagonal and ans= 1 0 0
0’s elsewhere.
0 1 0
0
2
3
4
zeros(m,n)
ones(m,n)
rand(m,n)
Create an array of all zeros
zeros(2,3)
* Returns an m-by-n matrix of zeros.
ans =
1
0
0
0
0
0
0
1
1
1
1
1
1
Create an array of all ones
ones(2,3)
* Returns an m-by-n matrix of ones
ans =
Uniformly distributed random number (0,1)
0
rand(2,3)
* Returns an m-by-n matrix containing pseudo-random ans = 0.1576 0.9572 0.8003
values drawn from the standard uniform distribution on
0.9706 0.4854 0.1419
the open interval (0,1)
5
randn(m,n)
Normally distributed random numbers (Gaussian)
randn(2,3)
* Returns an m-by-n matrix containing pseudo-random ans= -0.1241 1.4090 0.6715
values drawn from the standard normal distribution
1.4897 1.4172 -1.2075
“Gaussian”.
6
randi(imax,m,n) Uniformly distributed pseudo-random integers
* Returns an m-by-n matrix containing pseudorandom
integer values drawn from the discrete uniform
distribution on range start by 1 to imax
11.
randi(7,2,3)
ans =
6
5
6
7
6
3
Structures: Conditions, Case, Loops, and User-Defined Function
Table Error! No text of specified style in document..46: Structures: Conditions, Case, Loops, and User-Defined
Function
#
Command
Usage
1
if condition
Execute statements if the condition is true A=8;
and end up the if condition.
if A<10
Statements
end
Example
A = 10;
end
2
if condition
Statement
elseif condition
Execute statements if the condition is true A = 8
else check the other condition if it is true
if A<10
then execute the second set of statements
else execute the other statements and end A = 10;
123
Statement
up the if condition.
else
elseif A ==10
A=20;
Statement
else
end
A=30;
end
3
for n = StNum:Inc:EnNum
statement
end
For loop repeat the execution of
statements several time starting from
StNum with an increment of Inc and end
value of EnNum
% Using loop to find the factorial of a
% number
Num = 4;
Fact=1;
for n=1:Num
fact=fact*n
end
4
switch switch_expression
end evaluates an expression and chooses to execute
one of several groups of statements. Each choice is a
case case_expression
Statement
case case_expression
Statement
otherwise
1.
2.
Statement
end
“switch switch_expression, case case_expression,
x=input('Enter the
course number(1: Math,
case.
2: Engineering, 3:
The switch block tests each case until one of the case Control) to get the
name of the
expressions is true. A case is true when:
instractor\n')
For numbers, case_expression == switch_expression.
For character
vectors, strcmp(case_expression,switch_expression)
== 1.
3.
For objects that support
the eq function, case_expression == switch_expressi
on.
4.
switch x
For a cell array case_expression, at least one of the
elements of the cell array
matches switch_expression, as defined above for
numbers, character vectors, and objects.” [1]
case 1
disp('Mohammed')
case 2
disp('Ahmed')
case 3
disp('Khaled')
end
124
5
function
A User-defined function with output
[outputArg1,outputArg2] =
arguments indicated with
untitled6(inputArg1,inputArg2)
outputArg1 and OutputArg2. The current
%UNTITLED6 Summary of this name of the function untitled6 but could
function goes here
be changed. The current number of inputs
of this function is two which are inputArg1
% Detailed explanation goes
and inputArg2 but could have more than
here
two. The definition of the function will be
inside the function and not outside the end
outputArg1 = inputArg1;
line.
outputArg2 = inputArg2;
Note: there is two way to define the userend
defined function. First by using a function
file, but you need to keep your .m file of
the main code with the same location as
your user-defined function. The second
method is to keep your user-define
function at the end of your .m file code.
data1=[2 4 5];
data2=[10 20 30];
[a,b,c]=mohfunction
(data1,data2)
%% Defining Function at
the end of the code or
in a separate .m file
function
[mult,div,dist] =
mohfunction(x1,x2)
mult=x1.*x2;
div=x1./x2;
dist=sqrt(x1.^2+x2.^2);
end
5.
Symbolic Commands and Functions
Table Error! No text of specified style in document..47: Symbolic Commands and Functions [8]
#
Command
Usage
Example
1
syms x
creates symbolic variables x. syms x
Separate different variables by
spaces
2
ezplot(f,[min,max])
plots a symbolic expression,
equation, or function f over the
specified range of [min, max]
3
pretty(f)
prints f in a plain-text format
that resembles typeset
mathematics.
pretty(yt)
%result
exp(-8 t) - exp(-4 t) 2 + 1
125
4
solve(f,x)
solve(f)
solves the equation f for the
variable x
syms x y
f=(x-4)^2
solve(f)
ans= 4
4
5
[y1 y2 y3]=solve(f1,f2,f3)
solves the system of equations syms x y z
f1, f2, f3 ,… etc and place the
syms x y z
solution to the variables y1, y2,
y3, …etc
f1 = x^2+y^2+z^2-2
f2 = x+y-1
f3=y+z-1
[r1 r2 r3] = solve(f1, f2, f3)
ans= r1 = 1
-1/3
r2 = 0
4/3
r3 = 1
-1/3
6
limit(f,x,a)
returns the Bidirectional Limit limit(1/x,x,inf)
of the symbolic expression f
ans = 0
when x approaches a.
7
diff(f,x ,n)
computes the n th derivative of syms x
f with respect to the variable x
f= sin(x)
subplot(2,1,1)
ezplot(x,f,[-2*pi 2*pi])
f2=diff(f,x,1)
subplot(2,1,2)
ezplot(x,f2,[-2*pi 2*pi])
8
int(f)
int(f,x,a,b)
* computes the indefinite
integral of f.
* computes the definite
integral of f with respect to x
from a to b.
syms x
f=x^3
int(f)
ans = x^4/4
126
9
subs(f,x,v)
Symbolic substitution: returns syms x
the value of the function f after
subs(x^3,x,2)
substitute the value of v
instead of the variable x
ans = 8
10
expand(f)
Write the function f
syms x y
(polynomial) as a product of its
expand((x+y)^2)
factors.
ans = x^2 + 2*x*y + y^2
11
factor(f)
Returns the prime factorization syms x y
of the polynomial f
factor(x^2 + 2*x*y + y^2)
ans=(x + y)^2
12
simplify(f)
Simplify the expiration:
syms x y
performs model-reduction-like
simplify(sin(x)^2+cos(x)^2)
techniques to detect and
eliminate redundant copies of ans = 1
uncertain elements.
127
References
[1] “MathWorks - MATLAB Documentation R2020b,” MathWorsks, 13 January 2021. [Online]. Available:
https://www.mathworks.com/help/. [Accessed 13 January 2021].
[2] N. S. Nise, Control Systems Engineering, 6th ed., Pomona: John Wiley & Sons, Inc., 2011.
[3] A. A. Al-Shaikhi, H. Koroglu and Shams-ur-Rehman, EE 380 Automatic Control, Dhahran: King Fahd
University of Peteroleum and Minerals (KFUPM), 2013.
[4] A. A. Al-Shaikhi, A. Masoud, B. Liu, H. Koroglu, S. ur Rehman and S. Khan, EE 380 Lab manual - Automatic
Control, Dhahran: King Fahd University Of Petroleum & Minerals (KFUPM), 2018.
[5] B. Messner and D. Tilbury, “Introduction: PID Controller Design,” University of Michigan, Carnegie mellon
University, Unniversity of Detroit Mercy, & MathWorks, 2017. [Online]. Available:
https://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=ControlPID. [Accessed 8
January 2021].
[6] M. Maldini, “PID control explained: A zero preparation starting point,” 17 December 2018. [Online].
Available: https://maldus512.medium.com/pid-control-explained-45b671f10bc7. [Accessed 8 January
2021].
[7] R. C. Dorf and R. H. Bishop, Pearson New International Edition Modern Control Systems, Harlow: Pearson,
2014.
[8] A. Muqaibel and M. Tamim, Computation and Computer Programs for Electrical Engineers with Emphasis
on MATLAB Ver. 1.0, Dhahran: King Fahd University of Petroleum & Minerals Electrical Engineering
Department, 2012.
[9] “MATLAB Operators and Special Characters,” MathWorks, 7 January 2021. [Online]. Available:
https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-specialcharacters.html?s_tid=doc_ta. [Accessed 7 January 2021].
128
Download