Please use MatLab to do the following questions: 1.Plot pdf and cdf for geometri
ID: 3809029 • Letter: P
Question
Please use MatLab to do the following questions:
1.Plot pdf and cdf for geometric distribution, with N=100 and three different values of p: 0.3, 0.5 and 0.7. Save the figures as .jpg files. Hint: use functions geopdf and geocdf in MATLAB.
2.You have three dice. Each die has equal probability 1/6 to land on numbers 1,..,6. You roll the dice and record the sum of the three numbers you obtain. If the sum is 3 or 18, you win the game. You always play this game until you win. Let Y denote the number of trials it took you to win (rolling 3 dice is a trial). After 1000 victories you have a vector of 1000 Y values. Plot the histogram of the obtained Y values. Add graphical parameters to your plot and save it as a .jpg file. Compare your histogram with the pdf plot obtained in the previous problem.
Explanation / Answer
1)
x = 1:100;
%pdf
y1 = geopdf(x,0.3) %p = 0.3
y2 = geopdf(x,0.5) %p = 0.5
y3 = geopdf(x,0.7) %p = 0.7
%cdf
z1 = geocdf(x,0.3) %p = 0.3
z2 = geocdf(x,0.5) %p = 0.5
z3 = geocdf(x,0.7) %p = 0.7
%plot pdfs
figure();
plot(x,y1,'kd')
figure();
plot(x,y2,'kd')
figure();
plot(x,y3,'kd')
%plot cdfs
figure();
plot(x,z1,'b+')
figure();
plot(x,z2,'b+')
figure();
plot(x,z3,'b+')