Matlab is recommended, but you can choose whatever language you prefer. Please a
ID: 3112004 • Letter: M
Question
Matlab is recommended, but you can choose whatever language you prefer. Please attach your codes to the submission.
Answer the following simulation related questions: (a) Why is it important to use confidence intervals in discussing the results of simulations studies? (b). For the random number generator given below determine the Z_i and U_i values for a complete cycle. Z_i = (7Z_i - 1 + 1)(mod 31), U_i = Z_i /31 with Z_0 = 0 (c). Why are several seed values defined for random number generators? Define two seed values for the random number generator above that result in two different streams of numbers. (d). Develop an algorithm to generate values x_i for the random variable X with density function f(x) below. Use the first five U_i values from the generator in (b) above to determine five x_i values. f(x) = {l/3 for 0Explanation / Answer
%% Matlab code %%%
%%% b)
z(1)=0;
k=0; %% to check condition for cycle
for n=1:100
z(n+1)=mod(7*z(n)+1,31);
u(n)=z(n+1)/31;
for m=1:length(z)-1
if z(n+1)==z(m) %%% if matches cycle completed
k=1;
break;
end
end
if k==1
break;
end
end
% % c) let different seed value
z1(1)=2;
k=0; %% to check condition for cycle
for n=1:100
z1(n+1)=mod(7*z1(n)+1,31);
u1(n)=z1(n+1)/31;
for m=1:length(z1)-1
if z1(n+1)==z1(m) %%% if matches cycle completed
k=1;
break;
end
end
if k==1
break;
end
end
%%% d )
% % lets make a threshold of 1/24
th= 1/24 ;
for n=1:5
if (u(n) > 1/24 )
xi(n)=2*rand(1,1);
else
xi(n)=10*rand(1,1);
end
end