Simulation and Modelling - Module-1
Simulation and Modelling - Module-1
asia
1|Page
Department of MCA
LECTURE NOTE
ON
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
2|Page
Text Books:
References:
1. Jerry Banks, John S. Carson II, Barry L. Nelson, David M. Nicol, P. Shahabudeen,
Discrete-Event System Simulation, Fourth Edition, Pearson Publication.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
3|Page
1. Concept of a System 3
1.1 Discrete and continuous system
1.2 System Environment
1.3 Exogenous and Endogenous System
1.4 Deterministic and Stochastic System
2. Models 6
2.1 Types of Models
2.2 Principles used in modelling
3. Definition of Simulation and Application areas 13
4. Monte-Carlo technique of Simulation 14
5. Comparison of simulation and analytical methods. 15
6. Numerical Computation Technique 16
6.1 NCT for continuous models
6.2 NCT for discrete model
7. Program of a simulation study 21
8. Continuous system simulation 23
8.1 CSMP III program with details
9. Advantage of digital simulation over Analog simulation 30
10.Discrete & Continuous Probability function 31
11.Random number generation 34
11.1 Congruential generation
11.2 Mid-square method
11.3 Rejection method
12.Testing of random numbers 40
12.1 Kolmogorov-Smirnov Test
12.2 Chi - square Test with example
13.Generation of Stochastic Variables 46
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
4|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
5|Page
In static systems there are no changes over time where as in dynamic systems
the interactions cause changes over time.
Example 1
An aircraft system
Θi
Gyroscope Control surface Airframe
Desiredheading
Θο
Actual heading
Example 2
A factory system
Customer order
Production control department
Raw material
Purchasing Fabrication Assembly Shipping
department department department department
Finishing product
Consider a factory that make assembles parts for a product. Two major components of
the factory system are the fabrication department that makes the part & the assembly
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
6|Page
department that produces the product. A purchasing department maintains & a shipping
department dispatches the finished product. A production control department receives order
& assigns work to the other department.
Components of a system
Three basic components are:-
• Entity
• Attributes
• Activities
Example:-
In the factory system the entities are the department, orders, parts and
products.Attributes are such factors as the quantities for each order, type of part or number of
machines in a department.The activities are the manufacturing process of the departments.
System Environment
A system is often affected by changes occurring outside the system. Such changes
occurring outside the system are said to occur in the system environment. An important step
in modelling system is to decide upon the boundary between the system and its environment.
The term endogenous is used to describe activities occurring within the system.
Example: sports, cultural functions in a university system.
The term exogenous is used to describe the activities in the environment that affect the
system.
Example: strikes in a university system.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
7|Page
Deterministic
An activity is said to be deterministic where the outcome of an activity can be
described completely in term of its input,
Example: AND, OR, NOT operations.
Stochastic
An activity is said to be stochastic where the effects of the activity vary randomly
over various possible outcomes.
Example: Throwing a dice or tossing a coin.
Continuous system
Systems in which the changes are predominantly smooth are called continuous
system.
Example:
The movement of the aircraft occurs smoothly so aircraft system is a continuous
system.
Discrete system
Systems in which the changes are predominantly discontinuous are called discrete
system.
Example:
Changes in the factory occur discontinuously so factory system is a discrete system.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
8|Page
System modelling
The model is defined as the body of information about a system gathered for the purpose of
studying the system. The tasks of deriving a system model are divided into two subtasks.
They are
1. Establishing the model structure
2. Supplying the data
It determines the system boundary and identifies the entities, attributes and activities
of the system.
The data provides the values that the attributes can have and define the
relationships involved in the activities.
Types of models
MODELS
PHYSICAL MATHEMATICAL
SYSTEM
SIMULATION
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
9|Page
Physical models:
Physical models are based on some analogy between such systems as mechanical and
electrical or electrical or hydraulic. Here the system attributes are represented by such
measurements as voltage or the position of a shaft. The system activities are reflected in the
physical laws that derive the models.
Mathematical models:
The mathematical model use symbolic notations and mathematical equations to
represent a system. The system attributes are represented by variables and the activities that
represented by mathematical functions that interrelate the variables.
A second distinction is between static models and dynamic models. Static models can
only show the values that system attributes take where the system is in balanced. Dynamic
models follow the changes over time that result from system activities.
In case of mathematical model the third distinction is a technique by which the model
is solved that is actual values are assigned to system attributes.
System Simulation:
It is considered to be a numerical technique used in conjunction with dynamic models.
Models are of two types:
• Deterministic
• Stochastic
They are used in ship buildings, deciphering of DNA molecules, Wind Tunnels and Water
Tanks in the course of designing air craft or ship. They are also used for solving equations
with particular boundary condition. Example: Scale models.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
10 | P a g e
They rely upon an analogy between the system being studied and some other system
of a different nature.
The first figure represents the wheel suspension system of an automobile. It consists of mass (M) that
is subject to an applied force (F (t)) varying with time. A spring whose force is proportional to its
Extension and contraction and shock absorber that absorbs the damping force
proportional to the velocity of the mass. The motion of the system can be represented by the
following differential equation.
= =
= velocity
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
11 | P a g e
Where, M = Mass
x = Displacement of mass
The 2nd figure represents an electrical circuit with a resistance “R” and inductance “L”
and capacitance “C” connected in series with a voltage source that varies in time according to
the function E (t). Let “q” be the charge on the capacitance. This system can be represented
by the following equation-
=
Where, L = Inductance
R = Resistance
q = Charge on Capacitance
C = Capacitance
By comparing two equation of mechanical system and electrical system which are
similar to each other given below.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
12 | P a g e
Both the systems are analogues of each other and the performance of either can be
studied with the other. It is similar to modify the electrical system than to change the
mechanical system. Example: Two credit what effect a change in the shock absorber will
have on the performance of the car. It will only necessary to change value of resistance in the
electrical circuit and observe the effect on the way the voltage varies.
A static model gives the relationship between the system attributes when the system is in
equilibrium. Example: In marketing a commodity there is a balance between the supply and
demand for the commodity. Both factor depend upon price. The demand for a commodity
will be low when the price is high and it will increase as the price drops.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
13 | P a g e
PRICE
Equillibrium Point
QUANTITY
Q = a - bp
S = c + dp
S = Q (Equilibrium)
Q = Demand
P = Price
S = Supply
a, b, c, d are constants.
c + dp = a – bp (b + p) d = a - c
!
"#
It allows the changes of system attributes to be derived as a function of time. This derivation
may be made with analytical solution or with a numerical computation depending upon the
complexity of the model.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
14 | P a g e
a. Block Building
b. Relevance
c. Accuracy
d. Aggregation
Block Building:
The description of the system should be organized in a series of block. The aim is to simplify
the specification of the interaction with in a system. Each block describes a part of the system
that depends upon the few input variables and results in few output variables. The system as a
whole can be described in terms of interconnection between the blocks and can be
represented graphically as a simple block diagram. Example: The description of a factory is
an example of a block diagram where each department has been treated as a separate block
where the inputs and outputs being the work passed from department to department.
Relevance:
The model should only include those aspects of the system that are relevant to the study of
the objective. A relevant information should be excluded because it increases the complexity
of the model and causes more work in solving the model.
Accuracy:
The accuracy of the information gathered for the model should be considered.
Aggregation:
It is the extent to which the number of individual entities can be grouped together into larger
entities. In some studies it may be necessary to construct artificial entities through the process
of aggregation. Example: An economic or social studies usually treats a population as a
number of social classes and conduct the study as each social class as a distinct entity.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
15 | P a g e
Population
Government Home
Students Business Private Jobs
Jobs Makers
Earlier most experiments were carried out physically in the laboratories. Millions
were spent on physical models like network analysers, Aircraft flight, Simulators and
expensive experiments.
Simulation plays vital role in biology, sociology and economics, medicines etc.,
where experimenting could be very expensive dangerous or even impossible.
In field such as Biology and economics, the problems are large involving thousands of
variables and are complicated due to uncertainty.
There are many problems faced by management that cannot be solved by standard
operations research tools like linear and dynamic programming inventory and queuing. So a
business executive has to make a decision best on his intuition and experiment. But with
computer simulation he can make better and meaningful decisions. Simulation is widely used
for inventory control, facility planning, production scheduling etc.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
16 | P a g e
System Simulation:
It is defined as the technique of solving problems by the observations of performance
over time of a dynamic model of system. This definition includes the use of dynamic physical
models where the results are derived from physical measurements rather than numerical
computations.
(*+
a ,- b x
Figure - The Monte Carlo Method
For example, the integral of a single variable over a given range corresponds to
finding the area under the graph representing the function. Suppose the function f(x0) is
positive and has lower and upper bound a and b respectively and the function is bounded
above by the value c. The graph of the function is then contained within a rectangle with
sides of length (b-c) and c. If we are pick points at random within the rectangle and
determined whether they lie beneath the curve or not, it is apparent that, providing the
distribution of selected points is uniformly spread over the rectangle, the fraction of points
falling on or below the curve should be approximately the ratio of the area under the curve to
the area of the rectangle.
If ‘N’ points are used and ‘n’ of them fall under the curve, then approximately
n/N = $
& %
&'
The accuracy improves as the number N increases. When it is decided that sufficient points
have been taken, the value of integral is estimated by multiplying n with N by the area of
rectangle i.e.)c(b-a).
Computational Technique:-
For each point, a value of ‘x’ is selected at random between a and b, say x0. A second
random selection is made between 0 and c to give Y. If Y0 is <=f(x0), the point is accepted
in the count ‘n’, otherwise it is rejected and the next point is picked. This method often
based on integral of many variables by using a random number for each of the variables.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
17 | P a g e
Monte Carlo application are sometimes classified as being simulation. Simulation and
Monte Carlo method are both numerical computational technique but the difference is that
simulation applies to dynamic model whereas MonteCarlo technique applied to static
model.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
18 | P a g e
N
U
M
B
E
R
S
O
L
D
The horizontal line at H is the total market for houses. The curve for y indicates how
the number of houses sold increases with time. The slope of the curve (i.e., the rate at which y
increases) decreases as H-y gets less. This reflects the slowdown of sales as the market
becomes saturated. Mathematically, the trend can be expressed by the equation
Consider now a manufacturer of central air conditioners designed for houses. His rate
of sales depends upon the number of houses build. (For simplicity, it is assumed that all
houses will install an air conditioner.) As with house sales, the rate of sales diminishes as the
unfilled market diminishes.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
19 | P a g e
Let s be the number of installed air conditioners. Then the unfilled market is the
difference between the number of houses and the number of installed air conditioners. The
sales trend may be expressed mathematically by the equation
The change of s with time is also illustrated in Fig. 2. The two equation constitute a mode of
the growth of air conditioner sales. Because of its simplicity, it is in fact possible to solve the
method analytically. However, it quickly becomes insoluble if it is expanded to become more
representative of actual marketing conditions. The market limit, for example, may not be
stable. It could grow with population growth or fluctuate with economic conditions. The
coefficients that determine the rates of growth could be influences by the amount of money
spent on advertising, and there could be competitive influences, such as mobile homes or
apartment housing. These influences could also depend upon the population growth or
prevailing economic condition, and so further complicate the model.
The simple model, however, will serve to illustrate the general methods applied in
suppose that the computation is made at uniform intervals of time and that the calculation has
NUMBER SOLD
already progressed to the time ti when the two variables of the problem have the values yi and
si. Figure 2 shows the next step in the calculation.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
20 | P a g e
The calculation steps forward an interval ∆t to ti+1 = ti+ ∆t. The rates of sales are
assumed to be constant over the interval. The rates can be interpreted as the amount of
change per unit time. That is,
./0
.1
rate of change of y =
./0
.1
rate of change of x =
∆yi = k1 (H-yi) .1
∆xi = k2(H-xi) .1
Since yi and xi are known, it is a simple matter to get the values of y and x at time ti+1.
However, it will be noticed that the equation for ∆yi must be solved first to get the value of yi
needed in the equation for xi. In preparation for the solution of a continuous system model,
therefore, there must be a careful sorting of the equations to establish a workable order.
Repetition of the calculation using the new values of y and x produces the output at
the end of the next interval. As illustrated in Fig.2, the calculation is equivalent to calculation
the slope at each point and projecting a short straight line at that slope. The simulation output
is a series of such line segments, approximating the continuous curve that represents the true
output of the model.
There are many programming systems available that incorporate continuous system
simulation languages. They usually include a number of computational methods for the user’s
selection.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
21 | P a g e
1 0 45 45 45 N 57
2 45 16 61 61 Y 56
3 66 5 71 5 N 55
4 71 29 100 34 N 54
5 100 33 133 67 Y 53
6 138 25 163 25 N 52
7 163 21 184 46 N 51
Consider the above example, a clerk begins his days of works with a file of document
to be processed. The time taken to process them varies. He works through the file beginning
each document, as soon as he finishes the previous one except that he takes that 5min break if
at that time, he finishes a document is an hour or more, since he begins work or he left a
break. We assume that the time to process the documents are given. We will keep a count of
no. of documents left for processing. This count will be initially set to the no. of document at
the beginning of the day and we assume that no. of document arrive during the day. The
count will be decremented for each completed job and the work will stop when count goes to
zero.
The first column numbers the documents, the second column gives the time the clerk
begins to work for a document denoted by (Ts), the third column give the time required to
work on the document called as the work time(Tw), the fourth column gives the time at
which the document is finished processing in time (Tf), the fifth column contains the
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
22 | P a g e
cumulative time since work started on since the last break measured at the time each job is
completed (Tc), the sixth column contains the break flag, this take the value ‘Y’ ,if the clerk
should take a break after the ith document and the value ‘N’ if he should not. The clerk works
until there are no more documents to be processed. On the time he finishes the document
goes beyond some prescribed time limit representing the end of the working period. The
computation proceeds row by row and from left to right.
A possible solution is to explore to pass the model that can be solved analytically. The
result will help to guide the simulation technique.
When it is decided to simulate, we must plan the study by deciding upon the major
parameters to be varied, the no. of cases to be conducted and order in which runs are to be
made.
Given that, the simulation is to be on a digital computer and its program must be
written. The next stage is, executing a series of runs according to the study plan. The main
value of the early runs in a simulation study is to get insight in to general behaviour of the
system and to know which parameters are important for the system. This may lead to
reassessment of the model then results are verified and if found reasonable, simulation stops.
Given that, the simulation is to be on a digital computer and its program must be
written. The next stage is, executing a series of runs according to the study plan. The main
value of the early runs in a simulation study is to get insight in to general behaviour of the
system and to know which parameters are important for the system. This may lead to
reassessment of the model then results are verified and if found reasonable, simulation stops.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
23 | P a g e
Describe the
Problem
Define a Model
Y N
Write a
Program
Validate the
Model
Reasonable? N
Y N
Y Run N Y
Reasonable?
More? Verify Result Stop
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
24 | P a g e
PROGRESS OF SIMULATIONSTUDY
Describe the
problem
Define a
model
Simula N Reaso N
Use analytical
te? methods nable?
Y Y
Redefine
Plan the model
study
Write a
program
Validate the
model
Run the
model
N
Reaso
nable?
Y More N Reasonab Y
Verify result le?
runs? Stop
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
25 | P a g e
An initial state to describe the problem to be solved in a concise manner so that there
is a clear statement of what questions to be asked and what measurements needed to be taken
answer these questions.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
26 | P a g e
x K
D
f(t)
This system represents the suspension of an automobile wheel when the automobile
body is assured to be immobile in a vertical direction. The figure represents a mass ‘M’
which is subject to an applied force F(t) varying with time. A spring whose force is
proportional to its extension or contraction given by ‘K’ and a shock absorber which exerts a
damping force ‘D’ proportional to velocity of the mass.
If we pick a point of the wheel as a reference point from which to measure the vertical
displacement of the wheel, the variable ‘x’ represents the displacement of the point taking ‘x’
to be positive for an upward movement. The velocity of the wheel in the vertical direction is
the rate of change of displacement which is first differential.
3 =
43
41
The acceleration of wheel in the vertical direction is the rate of change of velocity
45 3
which is second differential i.e.3 = 415 , for mass ‘M’ and applied force KF (t).The equation of
motion in the absence of any other forces should be
This force is represented by ,where ‘D’ is the measure of viscosity of the shock
But the shock absorber exerts a resisting force that depends on the velocity of wheel.
absorber. The spring also exerts a resisting force which depends on the extend to
which it has been compressed, represented by K(x), where ‘K’ is a constant defining a
stiffness of the spring. Since both these forces oppose the motion of wheel they are to
be subtracted from the applied force to given following equation.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
27 | P a g e
PARAM D=(5.656,16.968,39.582,56.56)
X2DOT=(1.0/M)*(K*F-D*XDOT-K*X)
PRTPLT X
END
STOP
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
28 | P a g e
1 -
K
-
D
K Scale
Integrator Sign Inverter Integrator Sign Inverter
Summer Changer
CSMP III
It consists of three types of statement,
1. Structural Statement
2. Data Statement
3. Control Statement
Structural Statement
It defines the model; it consists of FORTAN like statement and functional blocks.
Data Statement
Control Statement
They specify option’s in assembly an execution of the program & the choice of
output.
Example:
X = 6Y/W+ (Z-2)
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
29 | P a g e
Functional blocks
1. INTEGRATOR
Y=$+ *#8 9!
Functional block=
Y=INTGRL(IC, X)
Y (0) =IC
2. LIMITOR
P1
P2
Y=P1, X<P1
Y=P2, X>P2
Y=Y=X1P1 ≤ X ≤ P2
3. STEP FUNCTION
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
30 | P a g e
Y=STEP (P)
Y=
Y=SIN(X)
Y=ABS(X)
DATA STATEMENT
INCON
CONST A=0.5
PARAM
CONTROL STATEMENT
TIMER
Ex:-
• If printed or print-plot output is required, control statement with the word PRINT and
PRTLT are follows by the names of variable.
• TITLE, LABLE is used to put heading on the printed and PRTLT output.
Example
Answer:-
¨ .
M =KF (t) – D –Kx
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
31 | P a g e
¨
=1/M {KF (t) – D -Kx}
.
PRTPLT X
END
STOP
CONST M=-1/3,F=1.0,K=-10
X3DOT=(1.0/-3.0)*{(15.0*X2DOT)+(50.0*XDOT)+(200.0*X)-10}
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
32 | P a g e
PRTPLT X
END
STOP
jntuworldupdates.org Specworld.in