Professional Documents
Culture Documents
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.
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);
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");
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)
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: