next up previous index
Next: Set Facts, Venn Diagrams Up: Sample Space 09/24 Previous: Problem Session,09/25/98: De Méré's

Another Matlab Example for dice game

Suppose we play a dice game where at each throw of a dice I win the number of points if the throw is even and lose the number of points if the throw is odd.

How much will I win or lose over 1000 games?

How much does one win or lose on average?

In order to solve this by simulation we write a separate matlab function by editing a file called dice.m accessible from where you are working from.

%%%%%%%%%%%dice.m file%%%%%

function [win,aver]=dice(B)
%Play the dice game B times
%Commands effect:
gains =    -1     2    -3     4    -5     6;
ans =-1     6    -3    -3     2    -1

%Call from matlab:
w =   563
a =    0.5630
w =    506
a =    0.5060
w =5469
a =0.5469
w =   484
a =    0.4840
w =        4971
a =    0.4971

Susan Holmes