Sunteți pe pagina 1din 5

MONTE CARLO

ASSIGNMENT-7
AKASH MAHALIK
150123004
1. Generate 50 randam numbers from geometric distribution of the form :
f (x; p) = pq i1 i = 1, 2, 0 < p < 1.

Draw the probability mass function.

P = 0.4
CODE:

v<-vector();

for(i in 1:50)
{
x=runif(1,0,1);
print (x);
v[i]=floor(log(x)/log(0.6))+1;
print (v[i]);
}
hist(v, col="red", freq=F);

The probability distribution :


2.Generate 50 random numbers from poisson distribution with mean 2. Draw the prob-
ability mass function and the cumulative distribution function.

CODE:

v<-array(50);
lambda<-2
for(j in 1:50)
{
u=runif(1,0,1);
i=0;p=exp(-lambda);
f=p;
while(u>f)
{
p=lambda*p/(i+1);
f=f+p;
i=i+1;
}
v[j]=i;
}

hist(v,freq=F, col="lightgreen");
plot(ecdf(v), col="green");

The probabilty distribution function :


The Cumulative distributive function :

3. Draw the histogram based 50 generated random numbers from the mixture of two
Weibull distributions :
f (x; 1 , 1 , 2 , 2 , p) = pf 1 (x; 1 , 1 ) + (1 p)f 2 (x; 2 , 2 )
where f 1 () and f 2 () are two Weibull distributions of the form : f (x; , ) = x
1 e (x)

where, 1 = 2, 1 = 1, 2 = 1.5, 2 = 1, p = 0.4

CODE:

v<-array(50)
for(i in 1:50)
{
u1=runif(1,0,1);
u2=runif(1,0,1);
if(u1<=0.4)
{
v[i]=(-log(u2))^(0.5);
}else
{
v[i]=(-log(u2))^(2/3);
}
}

hist(v, col="cyan");
HISTOGRAM:

S-ar putea să vă placă și