0% found this document useful (0 votes)
32 views

Simulation of Continuous and Discrete System

Uploaded by

xojeje7914
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Simulation of Continuous and Discrete System

Uploaded by

xojeje7914
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 81

Unit 2 Simulation of

Continuous and Discrete


System (7 Hrs)
Contents of the unit
• Continuous System Models, Analog Computer, Analog Methods,
Hybrid Simulation, Digital Analog Simulation, Feedback Systems

• Discrete Event Simulation, Representation of time, Simulation Clock


and Time Management, Models of Arrival Processes- Poisson
Processes, Non-stationary Poisson Processes, Batch Arrivals:
• Gathering statistics, Probability and Monte Carlo Simulation
Continuous System Models
• A continuous system is one in which the predominant activities of the
system causes smooth changes in the attributes of the system
entities.

• When continuous system is modeled mathematically, the variables of


model representing the attributes of system are controlled by
continuous functions.
Continuous System Models
• The distributed lag model is an example of a continuous model which
descries how the attributes of the system are related to each other in
the form of linear algebraic equations.

• In continuous system, the relationship between variables describe the


rate at which the value of variables change, so, these system consists
of differential equations.
Continuous System Models
• Continuous system simulation uses the notation of differential
equation to represent the change on the basic parameter of the
system with respect to time.

• The mathematical model for continuous system simulation is usually


represented by ordinary differential and partial differential equations.
Continuous System Models
• The simplest differential equation models have one or more linear
differential equation with constant coefficients.

• It is possible to solve model without the use of simulation technique.

• When nonlinearities are introduced into the model, it becomes


almost impossible to solve using analytical method.

• Simulation methods of solving the model do not change


fundamentally when nonlinearities occur.
Continuous System Models
• The method of applying simulation to continuous models can be
developed by showing their applications to models where the
differential equations are linear and have constant coefficients, and
then generalizing to more complex equations.
Differential Equation
• Many of the laws in physics, chemistry, engineering, biology and
economics are based on empirical observations that describe changes
in the states of systems.
• Mathematical models that describe the state of such systems are
often expressed in terms of not only certain system parameters but
also their derivatives.
• Such mathematical models which use differential calculus to express
relationship between variables are known as differential equations.
Differential Equation
• Number of Independent Variables
• An equation which uses differential calculus to express relationship
between variables is known as differential equations.
• Quantity being differentiated is called dependent variable and the
quantity with respect to which the dependent variable is differentiated is
called independent variable.
• The differential equations have applications in all areas of science and
engineering.
• Differential equations are used to model problems in science and
engineering that involve the change of some variables with respect to
another.
• Mathematical formulation of most of the physical and engineering
problems leads to differential equations of two types.
Differential Equation
• Ordinary Differential equations (ODE): If there is only one
independent variable the equation is called an ordinary differential
equation.
• Partial differential equations (PDE): If it contains two or more
independent variables, the derivatives will be partial and therefore,
the equation is called a partial differential equation
Differential Equation
Differential Equation
Differential Equation (Order and Degree of Differential
Equation)
Differential Equation
• We can solve the model without using simulation technique. That is
we can solve such equations using analytical methods.

• However when non-linearity involves into the model, it may be


impossible or at least very difficult to solve such model without
simulation
Differential Equations
• When more than one independent variable occurs in a differential equation
the equation is said to be partial differential equations.

• It can involve the derivatives of the same dependent variable with respect to
each of the independent variable.

• The differential equations both linear and non-linear occur frequently in


scientific and engineering studies.
• The reason is that the most of physical and chemical process involves rates of
change, which require differential equation to represent their mathematical
descriptions.
Differential Equation
• The differential equation with constant coefficients to describe the wheel
suspension system of an automobile can be given as:
• M +D+Kx = KF(t)

• Here the dependent variable x appears together


• with first and second derivatives single dot and
• double dot respectively.

• The simple differential equation can model the simplest continuous system and
they can have one or more linear differential equation with constant coefficients.
Differential Equation
• The quantity F(t) is an input to the system, depending upon the
independent variable t.
• A linear equation with constant coefficients is always of this form.
• A equation may be linear or non linear and of any order or may be
ordinary or partial.
Differential Equation
• The above equation describes the automobile wheel suspension
system is derived from mechanical principles.
• 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 can
represent the displacement of the point, taking x to be positive for
the upward movement.
• The velocity of the wheel, in the vertical direction, is the rate of
change of positions, which is the first differential .
• The acceleration of the wheel, in the vertical direction, is the rate of
change of the velocity, which is the second differential
Differential Equation
• The mechanical law that determines the relationship between applied force and
movement of a body states that the acceleration of the body is proportional to the force.

• The coefficient of proportionality between the force and acceleration is the mass of the
body; so in case of the automobile wheel, where the mass is M and the applied force is
KF(t), the equation of the motion in the absence of other force would be as follows:
• M = KF(t)

The shock observer exerts a resisting force that depends on the velocity of the wheel; the
force is zero when the wheel is at rest and it increases as the velocity rises.

• If we assume the force is directly proportional to the velocity , it can be represented as D


where D is the measure of the viscosity of the shock observer.
Differential Equation
• Similarly, the spring exerts a resisting force which depends on the
extent to which it has been compressed.
• Again, if the force is directly proportional to the compression, it can
be represented by Kx, where K is a constant defining the stiffness of
the spring.
• Since both of these forces oppose the motion, they subtract from the
applied force to give the following equation of the motion:
• M = KF(t)- DKx

• Transposing terms, we get


• M +D+Kx = KF(t)
Analog Computers
• The analog computers were used for the simulation of the discrete
system simulations as well continuous system simulations before use
of digital computers.

• There existed devices whose behavior is equivalent to a mathematical


operation such as addition, integration etc and putting together
combinations of such devices in a manner specified by a
mathematical model of a system allowed the system to simulated.

• The analog devices, by their nature, gave continuous outputs and so


lent themselves readily to the simulation of continuous systems.
Analog Computers
• These computers were primarily used for solving differential equation
and most used version of the computers was the direct current
amplifiers.

• The most widely used form of analog computer is the electronic


analog computer based on the use of high gain dc amplifiers, called
operational amplifiers.

• Voltages in the computer are equated to mathematical variables, and


operational amplifiers can add and integrate the voltages.
Analog Computers
• With appropriate circuits, an amplifier can be made to add several input voltage, each
representing a variable of the model, to produce voltage representing the sum of the
input of the model equation.

• Different scale factors can be used on the circuits to represent coefficients of the model
equation.

• All voltages can be positive of negative to correspond to the sign of the variable
represented.

• To satisfy the equations of the model, it is sometimes necessary to use a sign inverter,
which is amplifier designed to cause the output to reverse the sign of the input
Analog Computers
• Accuracy of these computers is low as fluctuations in the voltage
level cannot be controlled beyond a limit.
• Secondly, a number of assumptions are made in deriving the
relationships for operational amplifiers, none of which is strictly true,
so, amplifiers do not solve the mathematical model with complete
accuracy.

• Some of the components used in the analog computers are:


Analog Computers
• A digital computer is not subjected to the same type of inaccuracies.
• Virtually any degree of accuracy can be programmed and with the use
floating point representation of numbers, an extremely wide range of
variations can be tolerated.

• Integration of variables is not a natural capability of a digital computer, as it is


in an analog computer, so that integration must be carried out by numerical
approximation.

• Methods have been developed which can maintain a very high degree of
accuracy.
Analog Computers
• A digital computer has the advantages of being easily used for many
different problems.

• An digital computer must usually be dedicated to one application at a


time, although time-sharing sections of an digital computer has
becomes possible.
Analog Computers
• In spite of the widespread availability of digital computers, many users
prefer to use analog computers.

• There are several considerations involved. The analog representation of a


system is often more natural in the sense that it directly reflects the
structure of the system ; thus simplifying both the setting up of simulation
and interpretation of the results.
• Under certain circumferences, an analog computer is faster than a digital
computer, as it can be solving many equations in a truly simultaneous
manner; whereas a digital computer can be working in only one equation at
a time.
• Some of the components used in the analog computers are:
Components of analog Computer

Scalar
Analog Methods
• The general method by which analog computers are applied and can
be demonstrated using the second order differential equation
• M +D+Kx = KF(t)

• Solving the equation for the higher order derivative gives


• M = KF(t)- DKx

• Suppose a variable representing the input F(t) is supplied and assume


for the time being that there exist variables –x and .
Analog Methods
• These three variables can be scaled and added with a summer to
produce a voltage representing M
• Integrating this variable with a scale factor of 1/M produces .
Changing the sign produces - which supplies one the variables initially
assumed and a further integration produces -x, which was the other
assumed variable.
• For convenience, a further sign inverter is included to produce +x as
an output.
Example: Simulation of wheel suspension
System
M +D+Kx = KF(t)
M = KF(t)- DKx
Hybrid Computers
• The scope of analog computers has been considerably extended by
developments in solid-logic electronic devices.
• Analog computers always used a few-linear elements such as
multipliers or function generators.

• Originally, the analog devices were expensive to make. Solid logic


devices, in addition to improving the design and performance of
operational amplifiers, have made such non-linear devices cheaper
and cheaper to obtain.
Hybrid Computers
• They have also extended the range of devices.
• Among the elements that can easily be associated with analog
computers are circuits that carry out the logical operations of Boolean
algebra, store values for later use, compare values, operate switches
for controlling runs.

• The term hybrid computer has come to describe combinations of


traditional analog-computer elements, giving smooth, continuous
outputs, and elements carrying out such non-linear, digital operations
as storing values, switching and performing logical operations.
Hybrid Computers
• Originally, the term had the connotation of extending analog-computer capabilities, usually by
the addition of special-purpose and often specially constructed, devices

• More recently, few purely analog computers are built. Instead, computers with large numbers
of standard, non-linear elements are readily available

• Hybrid computers may be used to simulate systems that are mainly continuous, but do, in fact,
have some digital elements-for example, an artificial satellite for which both the continuous
equations of motion, and the digital control signals must be simulated.

• Hybrid computers are also useful when a system that can be adequately represented by an
analog computer model is the subject of a repetitive study.
Digital Analog Simulator
• To avoid the disadvantages of analog computers, many digital
computer programming language have been written to produce
digital-analog simulators.
• They allow or facilitate a continuous model to be programmed on a
digital computer in essentially the same way as it is solved on a analog
computer.
• The language contains micro instructions that carry the action of
addition, integration and sign changer.
Digital Analog Simulator
• A program is written to link together these micro-instructions, in
essentially the same manner as operational amplifiers are connected
in analog computers.
• More powerful techniques of applying digital computers to the
simulation of continuous system have been developed.
• As a result, digital-analog simulators are not now in extensive use.
Hybrid Simulation
• For most of studies the model is clearly either of a continuous or
discrete nature, and that is the determining factor in deciding whether
to use an analog or digital computer for system simulation.
• However, there are times when an analog and digital computers are
combined to provide a hybrid simulation.
• The form taken by hybrid simulation depends upon the application.
• One computer may simulating the system being studied, while the other
is providing a simulation of the environment in which the system is to
operate.
• It is also possible that the system being simulated is an interconnection
of continuous and discrete subsystem, which can best be modeled by an
analog and digital computer being linked together.
Hybrid Simulation
• The introduction of hybrid simulation required certain technological
developments for its exploitation.
• High speed converters are needed to transform signals from one form
of representation to the other.
• As a practical, the availability of mini-computers has made hybrid
simulation easier, by lowering costs and allowing computers to be
dedicated to an application.
Hybrid Simulation
• The term “hybrid simulation” is generally reserved for the use in
which functionality distinct analog and digital computers are linked
together for the purpose of simulation.
Feedback System
• A significant factor in the performance of many systems is that a
coupling occurs between the input and output of the system.
• The term feedback is used to describe the phenomenon.
• A home heating system controlled by a thermostat is a simple
example of a feedback system.
• The system has a furnace whose purpose is to heat a room and the
output of the system can be measured as root temperature.
• Depending upon whether the temperature is below or above the
thermostat setting, the furnace will be turned on or off, so that
information is being fed back from the output to the input.
• In this case, there are only two states, either the furnace is on or off
Feedback System
• An example of a feedback system in which there is a continuous
control is the aircraft system.
• Here the input is a desired heading and output is the actual heading.
• The gyroscope of the autopilot is able to detect the difference
between the two headings.
• A feedback is established by using the difference to operate the
control surface, since changes of heading will then affect the signal
being used to control the heading.
Discrete System Simulation
• In discrete system the changes in the system state are discontinuous.
• Each change in the state of the system is called an event.
• For example, the arrival or departure of a customer in a queue is an
event.
• That contrasts to continuous systems in which the state changes
smoothly with time.
• Simulation is the representation or imitation of a system by a
computer for the purpose of predicting the behavior of that system
under certain conditions.
Discrete System Simulation
• The model used in discrete system simulation has a set of numbers to
represent the state of the system.
• A number used to represent some aspect of the system state is called
a state descriptor.
• As the simulation proceeds , the state descriptors change value.
• We define a discrete event as a set of circumferences, that causes an
instantaneous change in one or more system state descriptors.
Discrete System Simulation
• Implicit in the definition is the assumption that the system change is
one that has been considered of sufficient importance to be
represented in the model.
• It addition, it is possible that two different events occur
simultaneously, or are modeled as being simultaneous , so that not all
changes of state descriptors occurring simultaneously necessarily
belong to a single event.
• The term simultaneously, of course, refers to the occurrence of the
changes in the system, and not to when the changes are made in the
model-in which, of necessity, the changes must be made sequentially.
Discrete System Simulation
• Discrete-event simulation is commonly used in research to study
large, complex systems which are not suitable for conventional
analytic approach.
• Some examples are the study of sea and network and telephone
exchange.
• Another use simulation is for tuning a design, an example is network
design.
Representation of time in Discrete Event
Simulation
• A system simulation must contain a number representing a time.
• The simulation proceeds by executing all the changes to the system
descriptors associated with each event, as the events occur, in
chronological order.
• The way in which events are selected for execution, particularly when
there are simultaneously events, is an important aspect of
programming simulations.
• The passage of time is recorded by a number referred to as clock time.
• It is usually set to zero at the beginning of a simulation and
subsequently indicates how many units of simulated time have passed
since the beginning of the simulation.
Representation of time in Discrete Event
Simulation
• Unless specifically stated otherwise, the term simulation time means the indicated
clock time and not the time that a computer has taken to carry out the simulation.

• As a rule, there is no direct connection between simulated time and time taken to
carry out the computations.

• The controlling factor in determining the computation time is the number of events
that occur.

• Depending upon the nature of the system being simulated and detail to which it is
modeled, the ratio of the simulated time to the real time taken can vary enormously.
Representation of time in Discrete Event Simulation

• If a simulation were studying the detailed workings of a digital computer system,


where real events are occurring in time intervals measured in fractions of
microseconds, the simulation, even when carried out by a high speed digital computer,
could easily take several thousands times as long as the actual system operation.

• Two basic methods exist for updating clock time.

• One method is to advance the clock to the time at which the next event is due to
occur.

• The other method is to advance the clock by small intervals of time and determine at
each interval whether an event is due to occur at that time
Representation of time in Discrete Event
Simulation
• The first method is referred to as event-oriented, and the second
method is said to be interval-oriented.
• Discrete system simulation is usually carried out by using the event-
oriented method, while continuous system simulation normally uses
the interval-oriented method.
• It should be pointed out, however, that no firm rule can be made
about the way time is represented in simulations for discrete and
continuous systems.
• It is not the case that, the event-oriented method is not necessarily
faster than the interval oriented method for discrete systems.
Representation of time in Discrete Event
Simulation
• Fixed time step Model: In a fixed time step (interval oriented) model,
a time is simulated by the computer.

• This timer is updated by a fixed time interval t, and the system is


examined to see if any event has taken place during this time interval.

• All events that take place during that interval are treated as if they
occurred simultaneously at the end of this interval
Representation of time in Discrete Event
Simulation
• Next Event Model: In a next event model(event-to-event) the
computer advances time to the occurrence of the next event, thus it
shifts from one event to the next; the system state does not changes
in between.
• When something of interest happens to the system, the current time
kept track of.
• The following flowchart shows both models
Arrival Process Or Pattern
• Any queuing system must work on something –customer, parts,
patients, orders etc.
• We generally called them as entities or customers.
• Before entities can be processed or subjected to waiting , they must
first enter the system.
• Depending on the environment, entities can arrive smoothly or in an
unpredictable fashion.
• They can arrive one at a time of in clumps (eg bus loads).
• They can arrive independently or according to some kind of correlation.
Arrival Process Or Pattern
• They can arrive independently or according to some kind of
correlation.
• A special arrival process, which is highly useful for modeling purposes,
is the Markov arrival process which refers to the situation where
entities arrive one at a time and the times between arrivals are
exponential random variables.
• This type of arrival process is memory-less, which means that the
likelihood of an arrival within the next t minutes is the same no
matter how long it has been since the last arrival.
• Examples are phone calls arriving at an exchange, customers arriving
at a fast food restaurant, hits on a web site and many others.
Arrival Process Or Pattern
• The usual way of describing an arrival pattern is in terms of the inter-
arrival time, defined as the interval between successive arrivals.
• For an arrival pattern that has no variability, the inter-arrival time is,
of course, a constant.
• Where the arrivals vary stochastically, it is necessary to define the
probability function of the inter-arrival time.
• Two or more arrivals may be simultaneous.
• If n arrivals are simultaneous, then n-1 of them have zero inter-arrival
times.
Poisson Process (stationary)
• Consider random events such as the arrival of jobs at a shop, the
arrival of e-mail server, the arrival of boats to a dock, the arrivals of
calls to the call center, the breakdown of machines in a large factory,
and so on.
• These events can described by a counting function N(t) defined for all
t ≥ 0.
• This counting function will represent the number of events that
occurred in [0,t].
• Time zero is the point at which the observation began, regardless of
whether an arrival occurred at that instant.
Poison Process (stationary)
• For each interval [0,t], the value N(t) is an observation of a random
variable where the only possible values that can be assumed by N(t)
are the integers 0,1,2,..
• The counting process, {N(t), t ≥ 0) is said to be a Poisson process with
mean rate λ if the following assumptions are fulfilled.
a. Arrivals occur one at a time.
b. {N(t), t≥0} has stationary increments: The distribution of the
numbers of arrivals between t and t + s depends only on the length
of the interval ‘s’, not on the starting point t. The arrivals are
completely random
Poison Process (stationary)
• C. {N(t), t>0} has independent increments: The number of arrivals
during nonoverlapping time intervals are independent random
variables. Thus, a large or small number of arrivals in one time
interval has not effect on the number of arrivals in subsequent time
intervals. Further arrivals occur completely at random, independent
of the number of arrivals in past time intervals.

• This is equivalent to saying that the number of arrivals per unit time is
a random variable with a Poisson’s distribution.
• This distribution is used when chances of occurrences of an event out
of a large sample is small
Poison Process (stationary)
• The Poisson distribution is the discrete probability distribution of the
number of events occurring in a given time period, given the average
number of times the event occurs over that time period.
• Let X be the discrete random variable that represents the number of
events observed over a given time period. Ley λ be the expected value
(average) of X.
• If follows a Poisson’s distribution, then the probability of observing k
events over time period is
• P(X=k) =
Example 1
• A computer repair person is “beeped” each time there is a call for service. The
number of beeps per hour is known to occur in accordance with Poisson’s
distribution with a mean of λ= 2 per hour.
• a. Find the probability of three beeps in the next hour.
• b. Find the probability of two or more beeps in a hour-period
• Solution:
• Here k = 3.
• The probability of three beeps in the next hour is calculated as
• P(X=k) = = = 0.18
• P(X=2)+P(X=3)+…… 1- (P(X=0)+P(X=1)
• P(2 or more) = 1-(P(0)+P(1)} = 0.592
Example 2
• In a single pump service station, vehicles arrive for fueling with an
average of 5 minutes between arrivals. If an hour is taken as unit of
time, cars arrive accordance to Poison’s process with an average of λ
=12 cars/hr.


Example 3:
• A major league Baseball park, five customers arrive at a concession
stand on average in a ten-minute period.
A. What is the probability that in a ten minute period exactly three
people will arrive at the concession stand
B. Find the probability of exactly 3 customers arriving in 20 minutes?
C. Find the probability of 3 or fewer customer’s arriving in 20 minutes?
D. Find the probability of more than 3 customers arriving in 20
minutes
• A: λ =5, t=1 , x= 3
• P(X=k) = = = 0.18
Example 4
• Suppose that a computer will make an average of 3 errors per 40
words of translation. Suppose we randomly selects a 1200 word
passage translated by this program. Assume that the Poisson
distribution applies
A. Determine the probability that no errors will be found
B. Calculate the probability that more than 14 errors will be found
C. Find the probability that fewer than 9 errors will be found.
Non Stationary Poisson Process
• Non-stationary Poisson Process (NSPP) is characteristics by λ(t), the
arrival rate at time t.
• The NSPP is useful for situations in which the arrival rates varies
during the period of interest such as meal time in a restaurants,
phone calls during the business hours etc.

Non Stationary Poisson Process
• When the Poisson’s process is with a rate function λ = λ(t), which
varies with time. Such a process is called non-stationary or no-
homogeneous Poison process.
• If {N(t):t≥0) is a Poisson’s process with a rate function λ(t), then an
increment, N(t)- N(s), giving the number of events in the time interval
(s,t) , has a Poisson’s distribution with parameter μ= dt and
increments over disjoint intervals are independent random variables.
Example
• Demand on a first aid facility in a certain location occur accordance to
a non-stationary Poisson’s process with the following rate function:
• λ(t) =
• where t is measured in hours from the opening time of facility. Find
the probability
• (a) two demands occur in the first hour of operation
• (b) two demands occurs in the second hour of operation
• (c ) one demand occur in the last three hours of operation
• (d) two demands occur in the first two hours of operation
Solution
• (a) The mean for the first hour of operation is μ =
• Hence P(N(1)-N(0) =2} = = 0.251

• (b) The mean for the second hour of operation is 3. It follows that the
number of events in the time interval (1,2) has the Poisson’s
distribution with mean 3.
• Therefore
• P{N(2)-N(1) = 2} = = 0.609
• (c ) The mean for the last three hours of operation is
• u = = 4.5

• Therefore P{(N(5)-N(2 =1)} = = 0.05

• (d) The mean for the first two hours of operation is:
• u = + = 4.5

• Therefore , N(2)- N(1’) has the Poisson’s distribution with mean 4.5.
• Thus, P{N(2)-N(0) = 2} = = 0.1125
Gathering Statistics
• Most simulation programming systems include a report generator to print out
statistics gathered during the run.
• The exact statistics required from a model depend upon the study being
performed, but there are certain commonly required statistics which are usually
included in the output.
• Among the commonly needed statistics are:
• Counts giving the number of entities of a particular type or the number of times
some event occurs.
• Summary Measures such as extreme values, mean values and standard
deviations
• Utilization defined as the fraction (or percentage) of time some entity is engaged.
Gathering Statistics
• Occupancy defined as the fraction (or percentage) of a group of
entities in use on average
• Distributions of important variables such as queue length or waiting
times.
• Transit Times, defined as the time taken for an entity to move from
one part of the system to some other part.
Gathering Statistics
• When there are stochastic effects operating in the system ,all these
system measures will fluctuate as simulation proceeds, and the
particular values reached at the end of the simulation are taken as
estimates of the true values they are designed to measure.

Monte Carlo Method/ Simulation
• Monte Carlo methods, or Monte Carlo experiments, are a broad class
of computational algorithms that rely on repeated random sampling to
obtain numerical results.
• It is a numerical computation method that consists of extensive
experimental sampling with random numbers.
• 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(x) is positive and has lower and upper bounds a and
b, respectively.
• Suppose, also, the function is bounded above by the value c.
Monte Carlo Method/ Simulation
• The graph of the function is then contained within a rectangle with sides
of length c and b-a.
• If we pick points at random within the rectangle, and determine 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 the 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,
Monte Carlo Method/ Simulation
• =

• The accuracy improves as the number of N increase.

• When it is decided that the sufficient points has taken, the value of
integral is estimated by multiplying n/N with the area of rectangle,
c(b-a)
Estimating the value of PI using Monte
Carlo Simulation
• The idea is to simulate random (x,y) points in a 2-D plane with domain
as a square of side 1 unit.
• We then calculate the ratio of number of points that lied inside the
circle and total number of generated points.
Estimating the value of PI using Monte
Carlo Simulation
Estimating the value of PI using Monte
Carlo Simulation
• We know that area of the square is 1 unit sq while that of circle is
• π *(1/2)2 = π/4
• Now for a very large number of generated points,

•=
Algorithm
1. Start
2. Initialize circle_point, square_points and interval to 0
3. Generate random point x
4. Generate random point y
5. Compute d = x*x + y*y
6. If d<=1 then increment circle_points
7. Increment square_points
8. Increment interval
9. If increment< NO_OF_ITERATIONS, then goto step 2
10. Calculate PI = 4*circle_points/square_points)
11. Stop

You might also like