Author
bharatipooja
View
221
Download
0
Embed Size (px)
7/29/2019 Simulation prac
1/28
Practical No: 1
Single channel queuing model.
Aim:-
Implement single channel queuing model using an excel
program. Perform the following tasks to implement the
following concept.
Write an excel program to do the following:
1.Use built in function to generate the n-digit randomnumbers.
2.Distribution of time between arrivals.a.Accept probability values for the interval-
arrival time between (1-6 minutes).
Generate the random digit assignment
b.Distribution of service time. Accept probvalues for the service time between(1-6 minutes). Generate the random- digit
assignment.
3.Total No. of customers N=20.4.Prepare a simulation table & answer the following
queries such as find
i) Avg. waiting time (in minutes)ii) Probability that a customer has to
wait.
iii) Probability of idle server.iv) Avg. Service time (in minutes)v) Avg. time between arrivals (in minutes)vi) Avg. waiting time of those who wait (in
minutes)
vii) Avg. time customer spends in thesystem(in minutes)
Concept:-
Its calling population, the nature of the arrivals,
the service mechanism, the system capacity, & the queuing
discipline, describes a queuing system.In the single channel queue, the calling population is
finite. Arrivals for service occur one at a time in a
random fashion; once they join the waiting line, they are
eventually served. In the addition, service times are of
some random length according to a probability
distribution, which does not change over time. The system
capacity has no limits. A single server or channel serves
units in order of their arrivals.
Arrivals & services are defined by the distribution of the
time between arrivals and the distribution of the service
times, respectively. For any single or multi channel queue,the overall effective arrival rate must be less than the
7/29/2019 Simulation prac
2/28
total service rate, or the waiting line will grow without
bound, they are termed explosive or unstable.Concepts in queuing system:
1.State: The no. of units in the system & the status ofthe server, busy or idle.
2.Event: Set of circumstances that cause an instantaneouschange in the state of the system.3.In a single channel queue there are only 2 possible
events that can change the state of the system. There
are entry of a unit into the system or the completion
of service.
4.The system includes a server, the unit being served &units in the queue.
5.Simulation clock is used to track the simulated time.
7/29/2019 Simulation prac
3/28
Practical No: 2
Multi-channel queuing model.
Aim:-
Implement Multi-channel queuing model using a C programwith one server getting higher performance. Perform the
following tasks to implement the following concept.
Write a C program to do the following:
1)Use built-in function to generate the n-digited randomnumbers
2)Distribution of inter-arrivals of cars.a) Accept probability values for the inter-arrival time
between (1-4 minutes).
Generate the random-digit assignment.
b) Service distribution of Baker. Accept probability
values for the service time between (3-6 min). Generatethe random-digit assignment.
c) Service distribution of baker. Accept probability
values for the service time between (3-6 min). Generate
the random-digit assignment
3)Total no. of customers N=20.4)Prepare a simulation table & answer the following
queries such as find.
1)Percentage of time Able & Baker individually werebusy over total service time.
2)Percentage of arrivals had to wait.3)Avg. Service time (minutes)4)Avg. time between arrivals (minutes)5)Avg. waiting time for all customers6)Avg. waiting time for all customers who had to
wait
Draw the conclusion regarding the system & cost of
waiting.
Concept:-
Its calling population, the nature of the arrival, the
service mechanism, the system capacity, and the queuing
discipline, describes a queuing system.
In the single channel queue, the calling population is finite.Arrivals of service occur one at a time in a random fashion;
once they join the waiting line, they are eventually served.
In the addition, service times are of some random length
according to, a probability distribution that does not change
over time. The system capacity has no limit. Units are served
in order of their arrivals by a single channel or server.
Arrivals & services are defined by a distribution of the
time between arrivals & the distribution of the service times,
respectively. For any single or multi channel queue, the
overall effective arrival rate must be less than total service
rate, or the waiting line will grow without bound; they aretermed explosive or unstable.
7/29/2019 Simulation prac
4/28
Concepts in queuing systems:
1.State: The number of units in the system & the status ofthe server busy or idle.
2.Event: Set of circumstances that cause an instantaneouschange in the state of the system.
3.In the single channel queue, there are only two possibleevents that can change the state of the system. There arethe entries of the units into the system or the
completion of the service.
4.The system includes a server, the unit being served &units in the queue.
5.Simulation clock is used to track the simulated time.6.We find how well the current arrangement is working.
7/29/2019 Simulation prac
5/28
Practical No: 3
Inventory system
Aim:
Simulate Inventory system The Newspaper Sellers
Problem
Perform the following:
1.Use the in-built function to generate the n-digitrandom number.
2.Random digit assignment for type of Newsday.3.Accept the probabilities for the 3 types of news days:
Good, Fair, & Poor.
4.Prepare the simulation table for purchase of 70newspapers & find out the total profit.
5.Total profit = (revenue from sales)-(cost ofnewspaper)- (lost profit from excess demand) + (salvagefrom sale of scrap papers)
6.For C/C++ programming use the library functions togenerate the n-digited random numbers.
Given:
Distribution of Newspapers Demanded
Demand Probability Distribution
Demand Good Fair Poor
40 0.03 0.10 0.4450 0.05 0.18 0.22
60 0.15 0.40 0.16
70 0.20 0.20 0.12
80 0.35 0.08 0.06
90 0.15 0.04 0.00
100 0.07 0.00 0.00
Random digit assignment for Type of Newsday
Accept the probability for the three type of news days:
7/29/2019 Simulation prac
6/28
Good, Fair and Poor.
Prepare the simulation table for Purchase of 70
newspapers and find out the total profit.
Total Profit= (revenue from sales)(Cost of newspapers)(lost profit from excess demand) + (Salvage from sale of
scrap papers).
Concept:-
An important class of simulation problems involves
inventory systems. A simple Inventory system includes a
periodic view length N, at which time the Inventory level is
checked. An order is make to bring the inventory up to the
level M. At the end of the first review period, an order
quantity, Q1, is placed. In the Inventory system the lead time(i.e. the length of time between the placement & the receipt
of an order) is zero. Since the demands are not usually known
with certainty, the order quantities are probabilistic. Demand
is uniform over the time period. One possibility is that
demands all occur at the beginning of the cycle. Another is
that the lead-time is random of some positive length.
If the amount in Inventory drops below zero, indicating a
shortage. These units are backordered; when the order arrives,
the demand for the backordered items is satisfied first. To
avoid shortage, a buffer, or safety, stock would need to becarried.
Carrying stock in inventory has an associated cost
attributed to the interest paid on the funds borrowed to buy
the items (this also could be considered as the loss from not
having the funds available for other investments purposes).
Other costs can be placed in the carrying or holding cost
column: renting of storage space, hiring guards, & so on. An
alternative to carrying high inventory is to make more
frequent reviews, & consequently, more frequent purchases or
replenishments. This has an associated cost: the orderingcost. Also, there is a cost in being short. Customers may get
angry, at subsequent loss of good will. Larger inventories
decrease the possibilities of shortages. These costs must be
traded off in order to minimize the total cost of an inventory
system.
The total cost (pr total profit) of an inventory system
is the measure of performance. This can be affected by the
policy alternatives; the decision maker can control the
maximum inventory level M, & length of cycle N.
7/29/2019 Simulation prac
7/28
Practical No: 4
Discrete Distributions
Aim:
Implement discrete distribution for statistical models with
discrete random variable.Perform the following task to show the concept.
a)Define discrete distribution.b)Describe the purpose of discrete distribution.c)Write C/C++/Excel code for
i) Bernoulli distribution.
1.Accept probability of success p, the probability offailure, no. of trials from the user.
2.Calculate probability mass function (pmf) P(X),mean E(X)& Variance V(X).
3.Display calculated terms.ii) Binomial distribution.
1. Accept probability of success p, the probability of
failure, number of trails from the user.
2.Calculate probability mass function (pmf) P(X),mean
E(X) & Variance V(X)
3.Display calculated terms.
iii) Geometric Distribution:
1.Accept probability of success p, the probability of failure,
number of trials x to achieve first success from the user
2.Calculate probability mass function (pmf) P(X), mean E(X) &Variance V(X)
3.Display calculated terms.
iv) Poisson Distribution:-
1.Accept the mean & variance from the user.
2.Calculate probability mass function (pmf)
3.Display calculated terms.
Concept:-
In modeling real world systems there are few situations wherethe actions of the entities within the system under study cannot
be completely predicted in advance. There may be many causes of
variations. Some statistical models can describe these
variations.
Sampling the appropriate parameters can develop an appropriate
model. The model builder selects a known distribution form; make
an estimate of the parameters of the distribution.
Discrete random variable:
Let X is a random variable. If the number of possible values
is X is finite, or countable infinite, X is called a discreterandom variable. The possible values of X may be listed as x1,
7/29/2019 Simulation prac
8/28
x2 In the finite case the list terminates. In the countableinfinite case the list continues indefinitely.
Discrete random variables are used to describe random
phenomenon in which only integer values can occur.
1)Bernoulli trials & Bernoulli distribution.Consider an experiment with n trials, each of which can
be a success or failure. These are called Bernoulli process if
the trials are independent; each trial has only two possible
outcomes (Success or Failure), & the probability of a success
remains constant from trial to trial.
Then p(x1, x2, x3 xn)= p1(x1). p2(x2). p3(x3).. pn(xn).& pj(xj)= p(xj) =p, xj=1=success, j=1,2,..,n.
=1-p=q xj=1=failure, j=1,2,.,n.=0 otherwise.
The mean = E(Xj) = 0 . q+1 . p = p.
The variance = V(Xj) = [(02
.q)+ (12
.p)]- p2
= p(1-p)
2) Binomial Distribution:-
The random variable X that denotes the number of
successes in n Bernoulli trials has a Binomial Distribution
given by p(x), where
p(x) = nCxpxqn-x , x=0,1,2,.....,n
= 0,
E(X) = np
V(X) = npq
3) Geometric distribution:-The Geometric distribution is related to the sequence of
Bernoulli trials; the random variable of interest, X, is
defined to be the number of trials to achieve the first
success. The distribution of X is given by:
p(x) = qx-1 p, x=1,2,.= 0 , otherwise
E(X) = 1/p
V(X) = q/p2
Geometric distribution is memoryless.
4) Poisson distribution:-The Poisson distribution describes many random processes.
The Poisson pmf is given by:
p(x) = e-@ @x
x!
E(X) = @ =V(X)
F(x) = e-@ @i/i!
7/29/2019 Simulation prac
9/28
Practical no 5
Continuous Distribution
Aim:-
Implement continuous distribution for statistical models
with discrete random variable.
Perform the following task to show the concept.
a) Define continuous distribution.b) Describe the purpose of continuous distributionc) Write Excel code for
i) Uniform distribution:
a) Accept parameters a,b, from the userb)Calculate Probability distribution function (pdf) f(X),
Cumulative distribution function (cdf) F(X), where X isdistributed uniformly between a & b.
c)Display calculated terms.
ii) Exponential distribution:
a) Accept parameters lamda from the user
b)Calculate Probability distribution function (pdf) f(X),
Cumulative distribution function (cdf) F(X)
c)Display calculated terms.
iii) Gamma distribution:
a) Accept parameters & from the userb)
Calculate Probability distribution function (pdf) f(X),Cumulative distribution function (cdf) F(X)
c) Display calculated terms.iv) Erlang distribution:
a) Accept parameters k & from the userb) Calculate Probability distribution function (pdf) f(X),
Cumulative distribution function (cdf) F(X)
c) Display calculated terms.v) Normal distribution:
a) Accept parameters mean & variance 2 & transformationvariable
b) z=t-/ from the user.c) Calculate Probability distribution function (pdf) f(X),
Cumulative distribution function (cdf) F(X)
d) Display calculated terms.vi) Weibull Distribution:
a) Accept parameters of shape >0, scale >0 & scale vfrom the user.
b) Calculate Probability distribution function (pdf)f(X), Cumulative distribution function (cdf) F(X)
c) Display calculated terms.
7/29/2019 Simulation prac
10/28
vii) Triangular Distribution:
a)Accept parameters a, b, c from the user where a
7/29/2019 Simulation prac
11/28
= 0, otherwise.
The cdf is given by
F(x) =0 x0 if its pdf is given by, f(x)=1* e
-1*
It is used to model interarrival times when arrivals are
completely random & to model service time that are highly
variable. In these instances, is the rate.F(x) = 0, x0
7/29/2019 Simulation prac
12/28
Practical No: 6
Generation of Random Numbers:
Aim: -
Implement Generation of Random Numbers using followingmethods:
a.Define Linear Congruential Method.b.Define Combined Linear Congruential Methodc.Write C/C++/Excel program for:
i) Linear Congruential Method.a)Accept constant multiplier a, increment c,
modulus m, and seed X0 from the user.b)Display random numbers.
ii) Combined Linear Congruential MethodConcept:-
Linear Congruential Method: -
The Linear Congruential Method, initially proposed
by Lehmer(1951), produces a sequence of integer X1, X2between zero and m-1 according to the following recursive
relationship:
Xi+1 = (aXi+ c) mod m, i = 0, 1, 2, . ------(1)The initial value X0 is called the seed, a is called
the constant multiplier, c is the incremental and m is the
modulus. If c!=0 in equation (1), the form is called the
mixed Congruential Method. When c=0, the form is known as
the multiplicative Congruential Method. The selection of
the value for a, c, m and X0 drastically affects the
statistical properties and cycle length. Variation of
equation (1), are quite common in the computer generation
of random numbers.
Combined Linear Congruential Method: -
As computing power has increased, the complexity of
the system that we are able to simulate gas also
increased. Random number generators will period 2
31
-1 =2*109.
One fruitful approach is to combine two or more
multiplicative congruential generators in such a way that
the combined generator has a good statistical property
and a longer period. The following result from
LEcuyer[1998] suggest how this can be done.
If Wi,1, Wi,2, ., Wi,k, are any independent, discretevalued random variables but one of them say Wi,1, is
uniformly distributed on the integer 0 to mi-2, then
7/29/2019 Simulation prac
13/28
k
Wi = Wi,j mod mi-1j=1
is uniformly distributed on the integer 0 to mi-2.To see how this result can be used to form combined
generator, let Xj,1, Xj,2, .., Xj, k be the ith output
from k different multiplicative congruential
generator, where the jth generator has prime modulus
mj, and the multiplier aj is chosen so that the
period is mj-1. Then the jth generator is producing
integer Xi,j , that are approximately uniformly
distributed on 1 mj-1 and Wi,j-1 is approximatelyuniformly distributed on 0 to mj-2 LEcuyer[1998]thus suggested combined generator of the form:
k
Xi = (-1)j-1Xi,j mod mi-1j=1
with
Xi/m1 Xi>0
Ri=
m1-1/m1 Xi=0
Notice that the (-1)j-1 Xi,j-1; for eg: if k=2, then
(-10 ) (Xi,1-1) (-11 ) (Xi,2-1) = 2 (-1j-1) (Xi,j)
The maximum possible period for such a generator is
(m1-1)(m2-1).(mk-1)P= 2k-1
which is achieved by the following generator.
7/29/2019 Simulation prac
14/28
Practical No: 7
Test for Random Number
Aim: -
Implement a menu driven program to test the Random
Number using following test:
1)Frequency Test:a)Chi-Square Test: Accept n random numbers, level of
significance number of intervals n, set ofobserved values & set of estimated values
b)Kolmogrov Test: Accept n random numbers, number ofobservations N, the set of Observations (Ri) where
1
7/29/2019 Simulation prac
15/28
Sampling distribution D is known and is tabulated as a
function of N, for testing against a uniform cdf, the
test procedure follows these steps:
Step1.: Rank the data from smallest to largest. Let
R(i) denote the ith smallest observation, so thatR(1)
7/29/2019 Simulation prac
16/28
Inverse Transform Technique
Aim: -
Implement Inverse Transform technique to find the randomvariants:
Perform the following task to show the concept.
a)Define Inverse Transformb)Write Algorithm for continuous distributions.Write C code for implementing Inverse Transform
technique.
i) Exponential distribution:a.Accept parameters & from the user.b.Calculate Probability distribution function
(pdf) f(X), Cumulative distribution function(cdf) F(X).
c.Display calculated terms.ii) Weibull distribution:
a.Accept parameters of shape >0, scale >0 &scale v from the user.
b.Calculate Probability distribution function(pdf) f(X), Cumulative distribution function
(cdf) F(X).
c.Display calculated terms.iii) Gamma distribution:
a.Accept parameters lamda from the user.b.Calculate Probability distribution function
(pdf) f(X), Cumulative distribution function
(cdf) F(X).
c.Display calculated terms.iv) Triangular distribution:
a.Accept parameters a, b, & c from the user,where abc.
b.Calculate Probability distribution function(pdf) f(X), Cumulative distribution function
(cdf) F(X), where X is distributed uniformly
between a, b.
c.Display calculated terms
Concept:-
The inverse transform technique can be used to sample
from the exponential, the uniform, the Weibull, and the
Triangular distributions and the empirical distributions
Additionally, it is the underlying principle for sampling
from a wide variety of discrete distributions. The technique
7/29/2019 Simulation prac
17/28
will be explained in detail for the exponential distribution
and then applied to other distributions. It is most straight
forward, but not always more efficient, technique
computationally.
(1) Exponential distribution:Exponential distribution, has probability density
function (pdf) given by
f(x)= e- x, x>= 00, x< 0
And cumulative distribution function (cdf) given by
F (x)= -xf (t)dt = 1- e-x, x>= 0
0, x< 0
The parameter can be interpreted as the mean number ofoccurrences per time unit. For e.g. if inter arrival times
X1, X2, X3 had an exponential distribution with rate , then could be interpreted as the mean number of arrivals pertime unit, or the arrival rate. Notice that for any i
E (Xi) = 1/So that 1/ is the mean inter arrival time. The goal is
to develop a procedure for generating values X1, X2, X3 that
have an Exponential distribution. The inverse transformtechnique can be utilized, at least in principle, for any
distribution, but it is most useful when the cdf, F(x), is of
such simple form that its inverse, F-1, can be easily
computed. A step-by-step procedure for the
Inverse transform technique, illustrated by the exponential
distributions, is as follows:
Step1: Compute the cdf of the desired random variable X. For
the exponential distribution, the cdf is F(x)= 1-e- x
,x>=0.
Step2: Set F(x)=R on the range of X. For the exponential
distribution, it becomes 1-e- x = R on the range x>=0.
Since X is a random variable, it follows that 1-e- x is also
a random variable, here called R. As will be showed later, R
has a uniform distribution over the interval (0,1).
Step3: Solve the equation F (x)=R on the range of X. For the
exponential distribution, the solution proceeds as follows:
1-e- x = R
-e- x =1- R
- x= In (1-R)
X = -1/ In (1-R) (I)
7/29/2019 Simulation prac
18/28
Equation I is called a random variate generator for the
exponential distribution. In general, equation I is written
as X = F-1(R). Generating a sequence of values is accomplished
through step 4.
Step4: Generate (as needed) uniform random numbers R1, R2,
R3, and compute the desired random variates by:Xi=F-1 (Ri)
For the exponential case, F-1 (R) = (-1/)In (1-R) byequation(I), so that
Xi = -1/1 In (1-R) (II)
For I = 1, 2, 3, one simplification that is usually employedin equation(II), is to be replace 1-Ri by Ri to yield
Xi = -1/1 In (1-R) (III)
which is justified since both Ri and 1- Ri are uniformly
distributed on (0,1)
(2)Weibull distribution: -
Step 1 : The cdf is given by
F (x)= 1-e-(x/) x>=0
Step 2 : F (x)= 1-e-(x/
) = R
Step 3 : Solving for X in terms of yields
X=[-In(1-R)]1-
(3)Gamma distribution
If X is following exponention with parameter
nthen X is gamma(n, ). To generate one observation or
i=1
One random variable from gamma, we have to first
generate n observations from exponential say X1, X2,...,
Xn then Y= X is random observation from gamma.n
Therefore Y=-1/*log(1-R)i=1
(4)Triangular distribution:
Consider a random variable X that has pdf.
This distribution is called Triangular distribution with
endpoints (0,2) & mode at 1. Its cdf is given by:
f(x) = 2(x-a) a x b(b-a)(c-a)
= 2(c-x) b x c(c-b)(c-a)
= 0 otherwise (I)
F(x) = (x-a)2 a x b(b-a)(c-a)
= (c-x)2 b x c(c-b)(c-a)
7/29/2019 Simulation prac
19/28
= 0 x>c (II)
By equation (I), 0
7/29/2019 Simulation prac
20/28
printf("| %d\t | %lf\t | %f\t
|\n",i+1,R[i],x[i]);
}
printf("-------------------------------------\n");
getch();
}
Output
Random Variate Generation for Exponential Distribution
------------------------------------------------------
Pdf of Exponential Distribution is lamda*e^(-lamda*x)
Cdf of Uniform Distribution is 1-e^(-lamda*x)
Enter the value of lamda(mean): 2
Enter the number of random numbers you are going to provide :
5
Random Numbers Generated are:
0.98 0.89 0.06 0.91 0.77
-----------------------------------------------
| i | R[i] |X[i]=-1/a*log(1-R[i]|
-----------------------------------------------
| 1 | 0.980000 | 1.956012 |
| 2 | 0.890000 | 1.103637 |
| 3 | 0.060000 | 0.030938 |
| 4 | 0.910000 | 1.203973 |
| 5 | 0.770000 | 0.734838 |
----------------------------------------------
7/29/2019 Simulation prac
21/28
(2) Weibull Distribution#include
#include
#include
#include
#include
int n,i;
double x[50];
float a,b,p;
float R[10],r1;
void main()
{clrscr();
printf("\nRandom Variate Generation for Weibull Distribution
\n");
printf("\n--------------------------------------------------\n");
printf("\nPdf of Weibull Distribution is
(beta/(alpha)^beta)*(x^beta-1)(e^(-x/alpha)^beta)\n");
printf("\nCdf of Weibull Distribution is 1-e^(-x/alpha)^beta\n");
printf("\nEnter the value of alpha(float): ");
scanf("%f",&a);
printf("\nEnter the value of beta(float): ");
scanf("%f",&b);p=a/b;
printf("\nEnter the number of random numbers you are going to
provide : ");
scanf("%d",&n);
randomize();
printf("\n\n Random Numbers Generated are:\n\n");
for (i=0;i
7/29/2019 Simulation prac
22/28
printf("------------------------------------------\n");
getch();
}
7/29/2019 Simulation prac
23/28
Output
Random Variate Generation for Weibull Distribution
--------------------------------------------------
Pdf of Weibull Distribution is (beta/(alpha)^beta)*(x^beta-
1)(e^(-x/alpha)^beta)
Cdf of Weibull Distribution is 1-e^(-x/alpha)^beta
Enter the value of alpha(float): 2.5
Enter the value of beta(float): 3.4
Enter the number of random numbers you are going to provide : 10
Random Numbers Generated are:
0.0400 0.6300 0.4200 0.5700 0.2400 0.4200 0.1600 0.5900
0.0500 0.6100
----------------------------------------------------------
| i | R[i] | X[i]=(-alpha/beta)*log(1-R[i])|
----------------------------------------------------------
| 1 | 0.040000 | 0.030016 |
| 2 | 0.630000 | 0.731068 |
| 3 | 0.420000 | 0.400535 |
| 4 | 0.570000 | 0.620566 |
| 5 | 0.240000 | 0.201792 |
| 6 | 0.420000 | 0.400535 |
| 7 | 0.160000 | 0.128201 |
| 8 | 0.590000 | 0.655587 |
| 9 | 0.050000 | 0.037716 |
| 10 | 0.610000 | 0.692359 |
----------------------------------------------------------
(3) Gamma Distribution
7/29/2019 Simulation prac
24/28
#include
#include
#include
#include
#includevoid main()
{
int n,i,j,n1;
float r[100],a,r1,r2,y,R[10];
clrscr();
printf("\nRandom variate generation using Gamma
Distribution\n");
printf("\n--------------------------------------------\n");
printf("\n\tConvolution Method");
printf("\n\t------------------");
printf("\nHow many gamma variates should be generated: ");scanf("%d",&n1);
for(j=0;j
7/29/2019 Simulation prac
25/28
Output
Random variate generation using Gamma Distribution
--------------------------------------------------
Convolution Method
------------------
How many gamma variates should be generated: 2
Enter the number of random numbers required to generate 1
gamma variate:5
Random Numbers Generated are:
0.3800 0.9200 0.4500 0.4600 0.2600
Enter the value of lamda: 0.5
Gamma variate is : 9.037786
Enter the number of random numbers required to generate 2
gamma variate:4
Random Numbers Generated are:
0.5300 0.8300 0.0800 0.2300
Enter the value of lamda: 0.3
Gamma variate is : 9.572418
(4)Triangular Distribution
7/29/2019 Simulation prac
26/28
#include
#include
#include
#include
#includeint a,b,n,i;
float x[50],r1;
double R[100];
void main()
{
clrscr();
printf("\nRandom Variate Generation for Triangular
Distribution \n");
printf("\n---------------------------------------------------
--\n");
printf("\nEnter the number of random numbers you are going toprovide : ");
scanf("%d",&n);
randomize();
printf("\n\n Random Numbers Generated are:\n\n");
for (i=0;i
7/29/2019 Simulation prac
27/28
Output
Random Variate Generation for Triangular Distribution
Enter the value of lamda(mean): 1
Enter the number of random numbers you are going to provide :
20
Random Numbers Generated are:
0.92 0.71 0.62 0.09 0.32 0.76 0.72 0.77
0.63 0.07
0.70 0.61 0.98 0.12 0.64 0.35 0.63 0.36
0.33 0.02
-----------------------------------------------
| i | R[i] | X[i]=-1/alog(1-R[i]|
-----------------------------------------------
| 0 | 0.920000 | 2.525729 |
| 1 | 0.710000 | 1.237874 |
| 2 | 0.620000 | 0.967584 |
| 3 | 0.090000 | 0.094311 |
| 4 | 0.320000 | 0.385662 |
| 5 | 0.760000 | 1.427116 |
| 6 | 0.720000 | 1.272966 || 7 | 0.770000 | 1.469676 |
| 8 | 0.630000 | 0.994252 |
| 9 | 0.070000 | 0.072571 |
| 10 | 0.700000 | 1.203973 |
| 11 | 0.610000 | 0.941609 |
| 12 | 0.980000 | 3.912023 |
| 13 | 0.120000 | 0.127833 |
| 14 | 0.640000 | 1.021651 |
| 15 | 0.350000 | 0.430783 |
| 16 | 0.630000 | 0.994252 |
| 17 | 0.360000 | 0.446287 || 18 | 0.330000 | 0.400478 |
| 19 | 0.020000 | 0.020203 |
---------------------------------------------
7/29/2019 Simulation prac
28/28
Practical No:09
Acceptance-Rejection Technique:
Aim: -
Implement methods for generation of random variates, X for a
given Distribution.
Perform the following tasks to show the concept:
a.Define Acceptance Rejection Technique.b.Write algorithm for Acceptance Rejection Technique.c.Write C/C++/excel code for implementing:
1)Poisson distributiona)Accept value of mean , arrivals n and
probability of random variate p.
b)Display the calculated Poisson variates.Concept:-
Method for generating random variates, X, uniformly
distributed between and one way to proceed would be to
follow these steps:
Step1 : Generate a random numbers R.
Step2 : a) If R>=1/4, accept X=R then goto step 3.
b) If R0 has pmfp(n)= P(N=n)=e-
n/n!, n=0,1,2,3,.N can be interpreted as the number of arrivals from
Poisson arrival process in one
unit of time.
Step1 : Set n=0, P=1
Step2 :.Generate the random numbers Rn+1 and replace P by P*Rn+1.Step3 : If P