Hello, I am currently really new with MATLAB and my lectures didn't really provide sufficient practice and exposure to how to function a MATLAB and I have an assignment due really soon so I hope I could get you guys to teach me how to deal with these questions.

1. The dice game craps is played as follows. The player throws two dice, and if the sum is seven or eleven, then he wins. If the sum is two, three of twelve, then he loses. If the sum is anything else, then he continues throwing until he either throws that number again (in which case he wins) or he throws a seven (in which case he loses). Estimate the probability that the player wins. You need to add commands to estimate the probability.

The code provided is, clear all

nreps=100000;

Event_W = 0;

for n=1:nreps

a= %Simulate the throw of two dice using the function 'randunifd'

if %Add code such that player obtain a 7 or 11

Event_W = Event_W +1;

elseif %Add code such that player obtains a 2,3 or 12

else

Throw = 1;

while %Add condition such that we keep playing until player either wins or loses

b= randunifd(1,6)+randunifd(1,6);

if %Add condition such that player wins

Event_W = Event_W+1;

Throw=0;

elseif %Add condition such that player loses

Throw=0;

end

a=b;

end

end

end

RelFreq = Event_W/nreps

I really have no idea how to do this at all. Your help would be greatly appreciated.

2. Consider the following experiment. We toss a fair coin 20 times. Let X be the length of the longest sequence of Heads.

(i) Estimate the probability function p of X. That is for x = 1, ....,20, estimate

$\displaystyle p(x) = P(X=x)$

(ii) Give an estimate of the mean value of X.

You need to add commands where indicated in the MATLAB file.

Here's the MATLAB file I got :

clear all

nreps=10000;

p=zeros(1,20); %p is a vector of size 20 such that p(i)=P(X=i)

for n=1:nreps

n_heads = 0; %Length of current Head sequence

max_heads= 0; %Length of maximum length sequence so far

for %Add code to toss a coin 20 times

if %Add condition to obtain a Head

n_heads = n_heads +1;

else

n_heads = 0;

end

if %Add condition to see if current sequence is the longest

max_heads = n_heads;

end

end

%Add code to increment p(max_heads) by 1

end

RelFreq = p/nreps

%Add code to estimate the mean of X

Thanks for your help! (: