computer simulation & modeling
TRANSCRIPT
-
8/2/2019 Computer Simulation & Modeling
1/134
Computer Simulation & Modeling
Paper I
Section I
-
8/2/2019 Computer Simulation & Modeling
2/134
Computer Simulation & Modeling
Computer Simulation & Modeling
Mahatma Gandhi Missions
College of Computer Science & Information Technology
At junction NH4 Sion-Panvel Expressway, Kamothe,Navi Mumbai-410 209.
M.Sc.(IT)PART-I
CERTIFICATE
This is to certify that Mr. kirtikumar dilip
giripunje of M.Sc.(IT)Part-I. Roll No. 17 has
completed the course of necessary practicals in
the subject of Computer Simulation & Modeling
under my supervision during the academic year
2010-2011.
-
8/2/2019 Computer Simulation & Modeling
3/134
Computer Simulation & Modeling
_________________
__________________Lecture-In-Charge
principal
_________________
__________________
External Examiner
External Examiner
INDEX
-
8/2/2019 Computer Simulation & Modeling
4/134
Computer Simulation & Modeling
Sr.
No
Date
Topic
Pag
e
No.
Sign
1. Single Sever Queuing
Model
2. Two Sever Queuing
Model
3. Newspaper Seller Problem
4. Discrete Distribution
1.Bernoulli Distribution
2.Binominal
Distribution
3.Geometric
Distribution
4.Poisson Distribution
5. Continuous Distribution
1. Uniform Distribution
-
8/2/2019 Computer Simulation & Modeling
5/134
Computer Simulation & Modeling
2. Exponential
Distribution
3. Gamma Distribution
4. Weibull Distribution
5. Normal Distribution
6. Triangular
Distribution
7. Erlang Distribution
6. Generate Random
Number
1. Linear Congruetial
Method
2. Multi Congruetial
Method
3. Inverse Transform
Tech.
4. Accept / Reject Tech.
-
8/2/2019 Computer Simulation & Modeling
6/134
Computer Simulation & Modeling
7
.
Random Number Test
1. Frequency Test
2. Run Up / Down
3. Run Above / Below
4. Autocorrelation
5. Poker Test
8. Goodness of Fit Test
Kolmogorov-Smirnov
Practical No. 1
Aim- To Implement a Single Server queuing problem
using EXCEL / C
-
8/2/2019 Computer Simulation & Modeling
7/134
Computer Simulation & Modeling
Code:
#include
#include
#include#include
#include
#include
void main()
{
clrscr();
int i,j;//with this statement diff random no will be generated
every time
time_t t;
srand((unsigned) time(&t));
//inter arrival variables
int arrtime[20],arrrandom[20];float arrprob[20],cdf=0,arrcdf[20];
//service time variables
int sertime[20],serrandom[20];float
serprob[]={0,0.05,0.1,0.2,0.3,0.25,0.1};//probability for
service tablefloat sercdf[20];
//simulation table variables
int rnoarr[20];
int rnoser[20];
int arrivaltime[20],clocktime[20];
int servicetime[20],servicein[20],serviceout[20];int waittime[20],idletime[20];
-
8/2/2019 Computer Simulation & Modeling
8/134
Computer Simulation & Modeling
float wait=0,idle=0,service=0,timespent=0;
//input arrival time table
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
9/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
10/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
11/134
Computer Simulation & Modeling
{
rnoarr[i]=random(1000);
}
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
12/134
Computer Simulation & Modeling
}
//calculating clock time
cdf=0;
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
13/134
Computer Simulation & Modeling
//calculating clock time
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
14/134
Computer Simulation & Modeling
wait=wait+waittime[i];
service=service+servicetime[i];
}
idle=idle/20;wait=wait/20;
service=service/20;
timespent=wait+service;
cout
-
8/2/2019 Computer Simulation & Modeling
15/134
Computer Simulation & Modeling
-
8/2/2019 Computer Simulation & Modeling
16/134
Computer Simulation & Modeling
Practical No. 2
Aim: To Implement a two sever system using EXCEL /
C
Code:
#include
#include
#include
#include
#include
#define SIZE 15
void main()
{
//initialization
int i,j,k,a,b;int cn,atime,stime,temp,rnum;
float time], ssrand[SIZE] ], bfiveA[SIZE],
bfiveB[SIZE];
float ccn[SIZE], aatime[SIZE], sstime[SIZE],
arand[SIZE], aarand[SIZE], srand[SIZE;
float second[SIZE], third[SIZE], fourA[SIZE],fourB[SIZE], afiveA[SIZE], afiveB[SIZE;
float aprob[SIZE], acdf[SIZE], sprob[SIZE],
scdf[SIZE];
float astime, asstime[SIZE], asprob[SIZE],
ascdf[SIZE];
float bstime, bsstime[SIZE], bsprob[SIZE],
bscdf[SIZE];
-
8/2/2019 Computer Simulation & Modeling
17/134
Computer Simulation & Modeling
int asrand[SIZE], bsrand[SIZE];
clrscr();
coutcn;
for(i=0;i
-
8/2/2019 Computer Simulation & Modeling
18/134
Computer Simulation & Modeling
for(j=0;j
-
8/2/2019 Computer Simulation & Modeling
19/134
Computer Simulation & Modeling
//beaker service();
coutbstime;
cout
-
8/2/2019 Computer Simulation & Modeling
20/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
21/134
Computer Simulation & Modeling
}
cout
-
8/2/2019 Computer Simulation & Modeling
22/134
Computer Simulation & Modeling
aarand[a]=rnum;
a++;
}
}
if(b
-
8/2/2019 Computer Simulation & Modeling
23/134
Computer Simulation & Modeling
third[i]=0;
afiveA[i]=0;
bfiveA[i]=0;
}
else
{
arand[-1]=1;
//val for 2nd
for(j=0;jarand[j-1] &&
aarand[i]=afiveB[i-1])
{
if(afiveB[i-1]>third[i])
{
afiveA[i]=afiveB[i-1];
}
else
-
8/2/2019 Computer Simulation & Modeling
24/134
Computer Simulation & Modeling
{
afiveA[i]=third[i];
}
bfiveA[i]=0;
bfiveB[i]=0;
}
else if(third[i]>bfiveB[i-1])
{
if(bfiveB[i-1]>third[i])
{bfiveA[i]=bfiveB[i-1];
}
else
{
bfiveA[i]=third[i];
}afiveA[i]=0;
afiveB[i]=0;
}
}
srand[-1]=1;
if(afiveB[i-1]
-
8/2/2019 Computer Simulation & Modeling
25/134
Computer Simulation & Modeling
{
fourA[i]=asstime[k];
fourB[i]=0;
break;
}
}
}
else
{
for(k=0;kbsrand[k-1] &&
ssrand[i]=afiveB[i-1])
{
afiveB[i]=fourA[i]+afiveA[i];
bfiveB[i]=0;
}
else if(third[i]>bfiveB[i-1])
-
8/2/2019 Computer Simulation & Modeling
26/134
Computer Simulation & Modeling
{
bfiveB[i]=fourB[i]+bfiveA[i];
afiveB[i]=0;
}
afiveB[-1]=0;
}
cout
-
8/2/2019 Computer Simulation & Modeling
27/134
Computer Simulation & Modeling
"
-
8/2/2019 Computer Simulation & Modeling
28/134
Computer Simulation & Modeling
Practical No. 3Aim: To Implement a Newspaper seller problem.
Code:
#include
#include
#include
#include
#include
#define SIZE 15
void main()
{
int i, j, k, a, b, rnum, avgdemand, value=0;
-
8/2/2019 Computer Simulation & Modeling
29/134
Computer Simulation & Modeling
int day, tdemand, type, salecost, salvagecost, price,
salvageprice;
int days[SIZE], demand[SIZE], trand[SIZE],
grand[SIZE], frand[SIZE], prand[SIZE];
int ttype[SIZE], ttdemand[SIZE], revenue[SIZE],
drand[SIZE], nrand[SIZE];
float cdf[SIZE], good[SIZE], poor[SIZE], fair[SIZE];
float lost[SIZE], salvage[SIZE], profit[SIZE];
float pg, pf, pp;
clrscr();coutday;
for(i=0;i>pg;
cout>pf;
cout>pp;
//cumulative prob
for(i=0;i
-
8/2/2019 Computer Simulation & Modeling
30/134
Computer Simulation & Modeling
{
if(i==0)
cdf[i]=pg;
else if(i==1)
cdf[i]=cdf[i-1]+pf;
else if(i==2)
{
cdf[i]=cdf[i-1]+pp;
value=cdf[i];
}}
coutprice;
cout>salecost;
cout>salvagecost;
cout
-
8/2/2019 Computer Simulation & Modeling
31/134
Computer Simulation & Modeling
cout>tdemand;
cout
-
8/2/2019 Computer Simulation & Modeling
32/134
Computer Simulation & Modeling
grand[i]=good[i]*100;
fair[i]=fair[i]+fair[i-1];
frand[i]=fair[i]*100;
poor[i]=poor[i]+poor[i-1];
prand[i]=poor[i]*100;
}
//big table
//random num for demand & newspaper
a=0,b=0;
while(a
-
8/2/2019 Computer Simulation & Modeling
33/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
34/134
Computer Simulation & Modeling
}
}
}
else if(ttype[j]==2) //fair
{
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
35/134
Computer Simulation & Modeling
if(ttdemand[j]
-
8/2/2019 Computer Simulation & Modeling
36/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
37/134
Computer Simulation & Modeling
for(k=0;k
-
8/2/2019 Computer Simulation & Modeling
38/134
Computer Simulation & Modeling
Output:-
1. Input Values
-
8/2/2019 Computer Simulation & Modeling
39/134
Computer Simulation & Modeling
2. Output Values
-
8/2/2019 Computer Simulation & Modeling
40/134
Computer Simulation & Modeling
-
8/2/2019 Computer Simulation & Modeling
41/134
Computer Simulation & Modeling
Practical No. 4
Aim: Simulate the following discrete distribution.
1. Program to find the probability mass function (pmf)p(X), meanE(X) and variance V(X), for theBernoulli destruction. Accept the probability of success
p, the probability of failure q, no. of trails n form the
user and display the value of pmf.
Code:
#include
#include
#include
#include
#include
void main(){
//initialization
int x,i,n;
float p,q,pdf,mean,variance;
float temp;
clrscr();
-
8/2/2019 Computer Simulation & Modeling
42/134
Computer Simulation & Modeling
cout>p;
if(p>0 && pn;
cout
-
8/2/2019 Computer Simulation & Modeling
43/134
Computer Simulation & Modeling
getch();
}
-
8/2/2019 Computer Simulation & Modeling
44/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
45/134
Computer Simulation & Modeling
2. Program to find the probability mass function (pmf)
p(X), mean
E(X) and variance
V(X), for theBinomial destruction. Accept the probability of success
p, the probability of failure q, no. of trails n form the
user and display the value of pmf.
Code:
#include#include
#include
#include
#include
void main()
{//initialization
int x,i,j,n;
float p,q,pdf,mean,variance;
float temp,r=1,s=1,t=1,c;
clrscr();
-
8/2/2019 Computer Simulation & Modeling
46/134
Computer Simulation & Modeling
cout>p;
if(p>0 && p
-
8/2/2019 Computer Simulation & Modeling
47/134
Computer Simulation & Modeling
}
//mean
mean=n*p;
variance=n*p*q;
cout
-
8/2/2019 Computer Simulation & Modeling
48/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
49/134
Computer Simulation & Modeling
3. Program to find the probability mass function (pmf)
p(X), meanE(X) and variance V(X), for thePoisson destruction. Accept the probability of success p,
the probability of failure q, no. of trails n form the user
and display the value of pmf.
Code:
#include
#include
#include
#include
#include
#define SIZE 15
void main()
{
float p,q,x,lam,a=1,pdf,mean,vari;
int n,i;
-
8/2/2019 Computer Simulation & Modeling
50/134
Computer Simulation & Modeling
clrscr();
coutp;
if (p>0 && p
-
8/2/2019 Computer Simulation & Modeling
51/134
Computer Simulation & Modeling
{
cout
-
8/2/2019 Computer Simulation & Modeling
52/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
53/134
Computer Simulation & Modeling
4. Program to find the probability mass function (pmf)
p(X), mean
E(X) and variance
V(X), for theGeometric destruction. Accept the probability of
success p, the probability of failure q, no. of trails n
form the user and display the value of pmf.
Code:
#include
-
8/2/2019 Computer Simulation & Modeling
54/134
Computer Simulation & Modeling
#include
#include
#include
#include
void main()
{
float p,q,x,pdf,mean,vari;
int n,i;
clrscr();
coutp;
if (p>0 && p
-
8/2/2019 Computer Simulation & Modeling
55/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
56/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
57/134
Computer Simulation & Modeling
Practical No. 5
Aim: Simulate the following continuous distribution
1. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Uniform distribution accept parameters a and b from
the user for the random variable X which is distributed
uniformly between a and b.
-
8/2/2019 Computer Simulation & Modeling
58/134
Computer Simulation & Modeling
Code:
#include
#include
#include
#include
#include
void main()
{
float pdf,cdf,a,b;
int n,i,x;
clrscr();
cout>a;
cout>b;
pdf=(1/(b-a));
cout
-
8/2/2019 Computer Simulation & Modeling
59/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
60/134
Computer Simulation & Modeling
2. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Exponential distribution accept parameters a and b
from the user for the random variable X which is
distributed uniformly between a and b.
Code :
#include#include
#include
#include
#include
void main()
{
float cdf,a,b,lam;
int i,x;
double pdf;
clrscr();
cout>lam;
cout
-
8/2/2019 Computer Simulation & Modeling
61/134
Computer Simulation & Modeling
cin>>x;
cout
-
8/2/2019 Computer Simulation & Modeling
62/134
Computer Simulation & Modeling
3. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Exponential distribution accept parameters a and b
from the user for the random variable X which is
distributed uniformly between a and b.
-
8/2/2019 Computer Simulation & Modeling
63/134
Computer Simulation & Modeling
Code :
#include
#include
#include
int facto(int be)
{
int i,prod=1;
for(i=be;i>=1;i--)
{
prod=prod*i;
}
return prod;
}
void main(){
float b,t,pdf,cdf,var,mean,sum=0.0;
clrscr();
coutb;coutt;
mean=(float)(1/t);
var=(float)(1/(b*t));
int b1=b-1;
cout
-
8/2/2019 Computer Simulation & Modeling
64/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
65/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
66/134
Computer Simulation & Modeling
4. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Weibull distribution.
Code :
#include
-
8/2/2019 Computer Simulation & Modeling
67/134
Computer Simulation & Modeling
#include
#include
int facto(int x)
{
int i,prod=1;
x=x-1;
for(i=x;i>=1;i--)
{
prod=prod*i;}
return prod;
}
void main()
{
float b,a,v,temp,temp1,x;float pdf,cdf,var,mean;
clrscr();
coutb;
couta;
coutv;
float b1,b2,b3,b4;
b1=(1/b)+1;
b2=facto(b1);
mean=v+(a*b2);
b3=facto((2/b)+1);
-
8/2/2019 Computer Simulation & Modeling
68/134
Computer Simulation & Modeling
b4=b3-(pow(b2,2));
var=a*a*b4;
cout
-
8/2/2019 Computer Simulation & Modeling
69/134
Computer Simulation & Modeling
cdf=1-exp(temp);
}
//end of cdf
cout
-
8/2/2019 Computer Simulation & Modeling
70/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
71/134
Computer Simulation & Modeling
5. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Normal distribution.
Code :
#include
#include
#include#include
#define SIZE 20
void main()
{
int i;
int rove,mue,range,x[SIZE];float a,b,c,d,pdf[SIZE];
clrscr();
cout>rove;
cout>mue;
coutrange;
cout
-
8/2/2019 Computer Simulation & Modeling
72/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
73/134
Computer Simulation & Modeling
-
8/2/2019 Computer Simulation & Modeling
74/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
75/134
Computer Simulation & Modeling
6. Program to find probability distribution function
(PDF) and cumulative distribution function (CDF) for
Triangular distribution.
Code :
#include
#include
#include
#include
#define SIZE 20
void main()
{
int i;
int alpha,beta,range,v;
float a,b,c,d,pdf[SIZE];
float x[SIZE];
clrscr();
cout
-
8/2/2019 Computer Simulation & Modeling
76/134
Computer Simulation & Modeling
cout>beta;
cout>v;
coutrange;
cout
-
8/2/2019 Computer Simulation & Modeling
77/134
Computer Simulation & Modeling
}
-
8/2/2019 Computer Simulation & Modeling
78/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
79/134
Computer Simulation & Modeling
Practical No.6
Aim: To generate random numbers and random
variates
1. To generate random numbers using linear
congruential method
Code:
#include
#include
#include
#include
#define SIZE 20
void main()
-
8/2/2019 Computer Simulation & Modeling
80/134
Computer Simulation & Modeling
{
//initialization
int i;
int num,a,c,x0,m,x[SIZE];
float r[SIZE],xr[SIZE];
clrscr();
coutx0;
cout>a;
cout>c;
cout>m;
x[0]=x0;
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
81/134
Computer Simulation & Modeling
r[i]=xr[i]/m;
}
//print
cout
-
8/2/2019 Computer Simulation & Modeling
82/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
83/134
Computer Simulation & Modeling
2. To generate random numbers using multiplicative
congruential method
Code:
#include
#include
#include
-
8/2/2019 Computer Simulation & Modeling
84/134
-
8/2/2019 Computer Simulation & Modeling
85/134
Computer Simulation & Modeling
xr[i]=x[i];
r[i]=xr[i]/m;
}
//print
cout
-
8/2/2019 Computer Simulation & Modeling
86/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
87/134
Computer Simulation & Modeling
-
8/2/2019 Computer Simulation & Modeling
88/134
Computer Simulation & Modeling
3. To generate random variates using Inverse
Transform Tecchnique
a. Exponential Distribution :
F(x) = 1-e x/
Where x>=0 and find F-1 (u) = - In (1-u)
Code :
#include#include
#include
#include
#include
#include
void main()
{
clrscr();
time_t t;
srand((unsigned) time(&t));
int n,i;
float a,b,x[100],r[100],lambda;cout
-
8/2/2019 Computer Simulation & Modeling
89/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
90/134
Computer Simulation & Modeling
B. Uniform Distribution
F(x) = x-a / b-a = R x = a + (b-a) R
Code:
#include
-
8/2/2019 Computer Simulation & Modeling
91/134
Computer Simulation & Modeling
#include
#include
#include
#include
void main()
{
clrscr();
time_t t;
srand((unsigned) time(&t));
int n,i;
float a,b,x[100],r[100];
cout
-
8/2/2019 Computer Simulation & Modeling
92/134
Computer Simulation & Modeling
}
Output:-
-
8/2/2019 Computer Simulation & Modeling
93/134
Computer Simulation & Modeling
4. TO generate random variates using Acceptance-
Rejection Technique
Code:
#include
#include
#include
#include
#include#include
#include
void main()
{
clrscr();
time_t t;
-
8/2/2019 Computer Simulation & Modeling
94/134
Computer Simulation & Modeling
srand((unsigned) time(&t));
int i=1,x,n=100;
float p,r,lambda,e;
cout
-
8/2/2019 Computer Simulation & Modeling
95/134
Computer Simulation & Modeling
x++;
p=p*r;
cout
-
8/2/2019 Computer Simulation & Modeling
96/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
97/134
Computer Simulation & Modeling
Practical No. 7
Testing of Random Number
1. Aim: To test the uniformity of the random numbers
using frequency test.
Code:
#include
#include
-
8/2/2019 Computer Simulation & Modeling
98/134
Computer Simulation & Modeling
#include
#include
void main()
{
clrscr();
int i,n,j,e=10,x[101],o[11];
float
r[101],chical,chitable,z,y,range[]={0.0,0.1,0.2,0.3,0.4,0.5,0.
6,0.7,0.8,0.9,1.0};
double c,alpha;cout
-
8/2/2019 Computer Simulation & Modeling
99/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
100/134
Computer Simulation & Modeling
if(r[i] < c)
{
o[j]=o[j]+1;
break;
}
else
c=c+0.1;
}}
cout
-
8/2/2019 Computer Simulation & Modeling
101/134
Computer Simulation & Modeling
}
cout
-
8/2/2019 Computer Simulation & Modeling
102/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
103/134
Computer Simulation & Modeling
2. Aim: To test the uniformity of the random no. using
Runs Ups & Runs Down as well as Runs Above & Below
Mean
i. Runs Ups & Runs Down have the mean & variance as
a = 2N -1 / 3 , 2a = 16N -29 / 90
Z0 = 1 -a / a
-
8/2/2019 Computer Simulation & Modeling
104/134
Computer Simulation & Modeling
Code:
#include#include
#include
#include
#include
#include
void main()
{
clrscr();
float r[21],meu,sigma,s,zcal,ztable;
int n,i,count=0,sign[21];
time_t t;
srand((unsigned) time(&t));
cout>n;
cout
-
8/2/2019 Computer Simulation & Modeling
105/134
Computer Simulation & Modeling
}
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
106/134
Computer Simulation & Modeling
else
sign[i]=0;
}sign[20]=1;
//calculating no. of runs
for(i=2;i
-
8/2/2019 Computer Simulation & Modeling
107/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
108/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
109/134
-
8/2/2019 Computer Simulation & Modeling
110/134
Computer Simulation & Modeling
Code:
#include
#include
#include
#include
#include
#include
void main()
{
clrscr();
float r[21],meu,sigma,s,zcal,ztable,sum=0,x;
int n=20,i,count=0,sign[21],n1=0,n2=0,alpha;
float a,b,c,d;
time_t t;
srand((unsigned) time(&t));
//generating random nos.
for(i=1;i
-
8/2/2019 Computer Simulation & Modeling
111/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
112/134
Computer Simulation & Modeling
else
{
sign[i]=1;
n2++;
}
}
//calculating no. of runs
for(i=2;i
-
8/2/2019 Computer Simulation & Modeling
113/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
114/134
Computer Simulation & Modeling
getch();
}
Output:-
-
8/2/2019 Computer Simulation & Modeling
115/134
Computer Simulation & Modeling
4. Aim: To test the uniformity of the random no. using
Autocorrelation
Code:
-
8/2/2019 Computer Simulation & Modeling
116/134
Computer Simulation & Modeling
#include
#include
#include
#include
#include
#include
void main()
{
clrscr();
time_t t;
srand((unsigned) time(&t));
float r[51],ztable,sum=0,d=0,e=0,row=0,sigma,zcal;
int i,n,j,lag,M=0,alpha,a=0,b=0,c=0;
cout
-
8/2/2019 Computer Simulation & Modeling
117/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
118/134
Computer Simulation & Modeling
//calculating row,sigma,zcal
for(j=0;j
-
8/2/2019 Computer Simulation & Modeling
119/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
120/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
121/134
Computer Simulation & Modeling
5. Aim: To test uniformity of the random no. using
Pokers test
Code:
#include
#include
#include
#include
-
8/2/2019 Computer Simulation & Modeling
122/134
Computer Simulation & Modeling
#include
#include
void main()
{
clrscr();
time_t t;
srand((unsigned) time(&t));
float r[51],ztable,sum=0,d=0,e=0,row=0,sigma,zcal;int i,n,j,lag,M=0,alpha,a=0,b=0,c=0;
cout
-
8/2/2019 Computer Simulation & Modeling
123/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
124/134
Computer Simulation & Modeling
{
b=i+j*lag;
c=i+(j+1)*lag;
d=r[b]*r[c];
sum=sum+d;
}
e=(float)1/(M+1);
row=(e*sum)-0.25;
d=0;d=13*M+1;
d=sqrt(d);
sigma=d/(12*(M+1));
zcal=row/sigma;
zcal=fabs(zcal);
//displaying the values
cout
-
8/2/2019 Computer Simulation & Modeling
125/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
126/134
Computer Simulation & Modeling
Output:-
-
8/2/2019 Computer Simulation & Modeling
127/134
Computer Simulation & Modeling
Practical No.8
Aim: To perform goodness of fit test using Kolmogorov
- Smirnov
Code:
-
8/2/2019 Computer Simulation & Modeling
128/134
Computer Simulation & Modeling
#include
#include
#include
#include
#include
void main()
{
clrscr();
int i,j,k=1,alpha,num=10;double D1[50],D2[50];
double Dcal,s;
double dtable,temp;
double cdf=0,arrival[50],normalize[50];
double r[50];
//generating interarrival times through random
function
for(i=0;i
-
8/2/2019 Computer Simulation & Modeling
129/134
Computer Simulation & Modeling
if(alpha==1)
dtable=0.490;
else if(alpha==5)
dtable=0.410;
else
dtable=0.368;
cout
-
8/2/2019 Computer Simulation & Modeling
130/134
Computer Simulation & Modeling
{
normalize[i]=arrival[i]/100;
}
for(i=0;i
-
8/2/2019 Computer Simulation & Modeling
131/134
Computer Simulation & Modeling
temp=0.0;
for(i=0;i
-
8/2/2019 Computer Simulation & Modeling
132/134
Computer Simulation & Modeling
cout
-
8/2/2019 Computer Simulation & Modeling
133/134
Computer Simulation & Modeling
}
else
{
cout
-
8/2/2019 Computer Simulation & Modeling
134/134
Computer Simulation & Modeling