SIMULATION AND MODELING
Instructor: Husnain Inayat Hussain
5/3/2025
Husnain Inayat Hussain
1
motivation / aspirations
• A brief introduction
• What do you expect from this course
5/3/2025
Husnain Inayat Hussain
2
ADMINISTRATIVE TRIVIA
5/3/2025
Husnain Inayat Hussain
3
books
• These presentations and board work should act as your notes
• Written notes (possibility)
• Various books / authors / references
1. Modeling and Simulation of Dynamic Systems
– Robert L. Woods, Kent L. Lawrence, Prentice Hall Latest Edition.
2. System Dynamics: Modeling and Simulation of Mechatronic
Systems using Bond Graph Theory
– Karnopp Dean C., Donald L. Margolis, Ronald C. Rosenberg;
Wiley Latest Edition
3. System Modeling and Simulation
– Frank L. Severance; Wiley 2001
4. System Dynamics
– Katsuhiko Ogata; Dorling Kindersly Publishers 2007
5/3/2025
Husnain Inayat Hussain
4
what is this course about then!
• Realize the notion of signals and systems
• What is meant by system?
• What is meant by signal?
• What is multi physics?
• What role does a model play in representing
physics?
• What is the role of noise?
• Why simulate (run) models at all?
• Which systems are feasible to model?
5/3/2025
Husnain Inayat Hussain
5
prerequisites
• Numerical Methods
• Linear Algebra
• Mathematics and Physics
• Computational Science
• Probability and Statistics
• Numerical Package
– MATLAB
5/3/2025
Husnain Inayat Hussain
6
course contents
• Refer to the PDF.
5/3/2025
Husnain Inayat Hussain
7
quizzes / exams / project
1. Assignments
2. Midterm
3. Quizzes
4. Final Exam
5. Practice Quiz
• Your Grades will be assessed according to:
• 0.1x1 + 0.25x2 + 0.15x3 + 0.5x4 + 0x5
5/3/2025
Husnain Inayat Hussain
8
modeling and simulations
DEFINITIONS
5/3/2025
Husnain Inayat Hussain
9
Modeling Simulation Cycle
5/3/2025
Husnain Inayat Hussain
10
signals
red = {0 1}
yellow = {0 1}
green = {0 1}
signals introduce
an input for the
incoming vehicles
and the output is
their decision
5/3/2025
Husnain Inayat Hussain
11
modeling and simulation (1/2)
It is a science which deals with the interaction of
components of a system by designing a suitable
representation of the system and then executing the
system with the help of some inputs to obtain some
outputs.
5/3/2025
Husnain Inayat Hussain
12
modeling and simulation (2/2)
• The term modeling
refers to the
development of a
mathematical
representation of a
physical situation.
• On the other hand,
simulation refers to the
procedure of solving the
equations that resulted
from model
development.
5/3/2025
Husnain Inayat Hussain
13
system
A system is a collection of components which are
joined by links through which various inputs
(signals) flow such that the components are
responsible to bring about changes to the inputs
and then these modified inputs are then processed
to obtain an output.
5/3/2025
Husnain Inayat Hussain
14
model (1/2)
• A model is a simplified representation of a system
which defines the connection between various
sub-components of the system and identifies the
functionality of each of the sub-components,
specifies the routes of each of the signals flowing
within the system and culminates the
combination of different inputs into different
outputs.
• Therefore a mathematical model is simply a
mathematical representation of the system.
5/3/2025
Husnain Inayat Hussain
15
model (2/2)
A model is an idealization of a physical situation into
some representation which may or may not fully
describe each and every details of the original
system.
Model
Physical situation
5/3/2025
Husnain Inayat Hussain
16
physical representation
A physical representation means an actual
embodiment of the system as governed by nature,
or as available by means of its original construction
by human beings.
5/3/2025
Husnain Inayat Hussain
17
how good is the model
• The quality or usefulness in a model is measured
by its ability to capture the governing physical
features of the problem. All successful models
unashamedly distort the inessentials in order to
capture the features that really matter.
• At worst, a model is a concise description of a
body of data. At best, it captures the essential
physics of the problem, it illuminates the
principles that underline the key observations,
and it predicts behaviour under conditions which
have not yet been studied.
5/3/2025
Husnain Inayat Hussain
18
simulation (1/2)
The process of solving the interaction of
components in the system in a particular manner as
governed by the physical laws or dynamics of the
problem is known as simulation.
5/3/2025
Husnain Inayat Hussain
19
simulation (2/2)
• Simulation refers to the procedure of solving the
equations that resulted from model development.
• For example, numerically solve a set of
differential equations with different
initial/boundary conditions.
5/3/2025
Husnain Inayat Hussain
20
What is Simulation?
• simulation
5/3/2025
Husnain Inayat Hussain
21
SYSTEM CLASSIFICATION
5/3/2025
Husnain Inayat Hussain
22
Static vs. Dynamic (1/2)
A static system is one where the output of the
system depends on the current input only.
input
environment
output
system
state
5/3/2025
Husnain Inayat Hussain
23
Static vs. Dynamic (2/2)
A dynamic system is one in which the output
depends not only on the current input but also
previous inputs or previous outputs.
input
output
system
state
5/3/2025
Husnain Inayat Hussain
24
Continuous vs. Discrete (1/2)
• A continuous system is one which represents
changes over variables without any finite
differences in the dependent or the independent
variable. This is to say that the system variables
are always available without any gaps.
• As an example let us consider the following very
simple continuous system
5/3/2025
Husnain Inayat Hussain
25
Continuous vs. Discrete (2/2)
• In reality systems are continuous but their study is
conducted at specific points in time or in space.
We call them as sampled quantities or sampled
variables.
• In some other situations, we obtain data from
some phenomenon and that too is obtained at
specific intervals.
• As an example, let us consider the following:
5/3/2025
Husnain Inayat Hussain
26
Linear vs. Non Linear (1/3)
• A system which is constructed by a linear
combination of its dependent variables.
• A sub category is the Linear Time Invariant systems
which are systems with constant coefficients.
• Another category is Linear Time Variant systems
whose coefficients are a function of the independent
variable.
5/3/2025
Husnain Inayat Hussain
27
Linear vs. Non Linear (2/3)
• A system which is composed of a non linear
combination of its dependent variables is
regarded as a non linear system.
• As an example consider the following non linear
system:
5/3/2025
Husnain Inayat Hussain
28
Linear vs. Non Linear (3/3)
• The biggest advantage of a linear system is
superposition of solutions.
• What that means is that given multiple inputs, all
we need is to identify all the solutions separately.
• Then obtain the final solution as a linear
combination of the individual solution.
5/3/2025
Husnain Inayat Hussain
29
Time vs. Event Driven (1/2)
• Time Driven systems are those which are running
at regular instances of time.
• Consider for example a model of an assembly
plant.
• On the assembly line, the components are coming
in one by one at a regular pace.
• Until there is some shutdown of some kind, this
process continues.
5/3/2025
Husnain Inayat Hussain
30
Time vs. Event Driven (2/2)
• Systems which are modeled such that activities
occur at some predefined event are termed as
event driven systems.
• As an example consider the NR pump valve which
only closes the influx of water once the water has
reached a desired height.
• A thermostat switch turns on or off only at the
attainment of particular temperature levels.
5/3/2025
Husnain Inayat Hussain
31
Deterministic vs. Stochastic (1/2)
• A system whose inputs and outputs behave in a
specific absolute manner.
• Examples are adders and multipliers.
• Time Driven models are a good candidate for
deterministic behavior.
• Consider Newton’s Cooling Law. The outcome at
any time is, to a great extent, deterministic except
a little noise (deviation from the theory) .
5/3/2025
Husnain Inayat Hussain
32
Deterministic vs. Stochastic (2/2)
• On the contrary a system which is provided with
random variable inputs tend to have a random
non deterministic output.
• Consider logic gates for example.
• Event driven systems are more likely to be
stochastic.
5/3/2025
Husnain Inayat Hussain
33
Lumped vs. Distributed (1/2)
• Distributed systems vary both in time and in
space.
• Example of a distributed system is a vibrating
string.
• Also electrical wires when they are not
approximated.
5/3/2025
Husnain Inayat Hussain
34
Lumped vs. Distributed (2/2)
• Lumped systems are those which vary only in
space or in time.
• Example is vibrating beads connected by massless
strings.
• Also resistors, capacitors and inductors provide a
lumped element simplification of a rather
complicated system.
5/3/2025
Husnain Inayat Hussain
35
EXAMPLES
5/3/2025
Husnain Inayat Hussain
36
VIBRATING STRINGS
5/3/2025
Husnain Inayat Hussain
37
Vibrating Strings (1/2)
Example of a distributed System
5/3/2025
Husnain Inayat Hussain
38
Vibrating Strings (2/2)
Example of a lumped System
5/3/2025
Husnain Inayat Hussain
39
NEURAL NETS
5/3/2025
Husnain Inayat Hussain
40
Physical Situation
synapse
axon
nucleus
cell body
synapses
dendrite
5/3/2025
Husnain Inayat Hussain
41
Mathematical Modeling
(2)
(2)
4
𝑎1 𝑤11
𝑊 (1) ∈ ℝ4×4
(2)
(2)
(3)
𝑠1
𝑊 (2) ∈ ℝ2×5
𝑎2 𝑤12
(2) (2)
𝑎3 𝑤13
(2)
=
(2)
𝑤1𝑖 𝑎𝑖
𝑖=0
(3)
𝑎1 =
1
(3)
1 + 𝑒 −𝑠1
𝑊 (3) ∈ ℝ1×3
𝑎(1)
(2)
(2)
𝑎4 𝑤14
(2)
(2)
𝑎0 𝑤10
𝑠 (2) = 𝑊 (1) 𝑎(1)
1
(2)
𝑎 =
(2)
1 + 𝑒 −𝑠
5/3/2025
𝑠 (3) = 𝑊 (2) 𝑎(2)
1
(3)
𝑎 =
(3)
1 + 𝑒 −𝑠
Husnain Inayat Hussain
𝑠 (4) = 𝑊 (3) 𝑎(3)
1
(4)
𝑎 =
(4)
1 + 𝑒 −𝑠
ℎ𝑤 𝑥 = 𝑎(4)
42
Simulation
5/3/2025
Husnain Inayat Hussain
43
CONVEYOR BELTS
5/3/2025
Husnain Inayat Hussain
44
Conveyor Belt Simulation (1/13)
• Consider a factory conveyor system in which
boxes arrive at the rate of one box each 10
seconds. Each box is one of the following weights:
5, 10 or 15 kg. However, there are twice as many
5 kg boxes and 15 kg boxes as 10 kg. boxes. How
do we model and simulate this?
5/3/2025
Husnain Inayat Hussain
45
Conveyor Belt Simulation (2/13)
incoming boxes
B4
B3
B2
B1
arrived boxes
conveyor
𝑤
Pr[𝑊 = 𝑤]
5
0.4
10
0.2
15
0.4
1.0
5/3/2025
Husnain Inayat Hussain
46
Conveyor Belt Simulation (3/13)
5/3/2025
Husnain Inayat Hussain
47
Conveyor Belt Simulation (4/13)
% Set simulation properties here for i = 1:numSim
numSim = 100;
simResult = zeros(3, 2);
r = 10 * rand();
simResult(1, 1) = 0.4;
if (r < 4)
simResult(2, 1) = 0.2;
w(i) = 5;
simResult(3, 1) = 0.4;
elseif ((r >= 4) && (r < 6))
weights = [5 10 15];
w(i) = 10;
elseif ((r >= 6) && (r <
w = zeros(numSim, 1);
10))
w(i) = 15;
end
% actual loop over 100
simResult(1, 2) = sum(w ==
simulation runs
5)/numSim;
% containing randomly arriving
simResult(2, 2) = sum(w ==
boxes
10)/numSim;
% with their specific weights
simResult(3, 2) = sum(w ==
and then
% calculation of the probability 15)/numSim;
to
5/3/2025
Hussain
48
% confirm
actual probabilityHusnain Inayatend
Conveyor Belt Simulation (5/13)
5/3/2025
Husnain Inayat Hussain
49
Conveyor Belt Simulation (6/13)
• Consider a factory conveyor system in which
boxes arrive as in the previous example. But now
they are shifted to a belt such that the belt exactly
holds three boxes at a time. The incoming boxes
keep pushing the boxes on the belt such that
there are exactly three boxes on the belt at all
times. The inputs are the incoming boxes and the
outputs are the weight at each box delivery. How
do we model and simulate this?
5/3/2025
Husnain Inayat Hussain
50
Conveyor Belt Simulation (7/13)
% Set simulation properties here for i = 1:numSim
numSim = 100;
r = 10 * rand();
% initialize a 100 x 1 weight
if (r < 4)
vector
w(i) = 5;
% and the same size x vector
elseif ((r >= 4) && (r < 6))
which
w(i) = 10;
% represents sum of the three
elseif ((r >= 6) && (r <
boxes
10))
% arriving at the conveyor
w(i) = 15;
w = zeros(numSim, 1);
end
x = zeros(numSim, 1);
if (i == 1)
% actual loop over 100
x(i) = w(1);
simulation runs
elseif (i == 2)
% containing randomly arriving
x(i) = w(1) + w(2);
boxes
else
% with their specific weights
x(i) = w(i) + w(i-1) +
and then
w(i-2);
% sum of the three boxes
end
dropping from
end
5/3/2025
Husnain Inayat
Hussain
51
% the
conveyor belt
Conveyor Belt Simulation (8/13)
5/3/2025
Husnain Inayat Hussain
52
Conveyor Belt Simulation (9/13)
• Consider a factory conveyor system again in which
boxes arrive but now their arrival times are
random. The arrivals now depend on triggering of
some event, however, to model this system we
need not bother ourselves with the nature of the
trigger. It is sufficient to state that this trigger is
random and causes the boxes to move. How do
we model and simulate this?
5/3/2025
Husnain Inayat Hussain
53
Conveyor Belt Simulation (10/13)
% generate random event times
here
% actual loop to draw circles to
% indicate arrival of boxes
% every random event
t = zeros(20, 1);
for i = 2 : length(t)
for j = 1 : 100
t(i) = t(i-1) + 20 * rand();
end
% waiting before the boxes
% finally arrive
% initialize number of boxes to
for k = 2 : 20
be
if (j-1 <= t(k)) &&
% zero and define teOld as the
(t(k) < j)
old
N = N + 1;
% even time also initially taken
te = j;
to
teOld = te;
% be zero
end
end
N = 0;
teOld = 0;
end
5/3/2025
Husnain Inayat Hussain
54
Conveyor Belt Simulation (11/13)
5/3/2025
Husnain Inayat Hussain
55
Conveyor Belt Simulation (12/13)
5/3/2025
Husnain Inayat Hussain
56
Conveyor Belt Simulation (13/13)
5/3/2025
Husnain Inayat Hussain
57
TIME FOR QUESTIONS /
DISCUSSION
5/3/2025
Husnain Inayat Hussain
58
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )