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 gains=[-1,2,-3,4,-5,6]; plays=unidrnd(6,B,1); win=sum(gains(plays)); aver=win %Commands effect: gains = -1 2 -3 4 -5 6; gains([1,6,3,3,2,1]) ans =-1 6 -3 -3 2 -1 %Call from matlab: [w,a]=dice(1000) w = 563 a = 0.5630 [w,a]=dice(1000) w = 506 a = 0.5060 [w,a]=dice(10000) w =5469 a =0.5469 [w,a]=dice(1000) w = 484 a = 0.4840 [w,a]=dice(10000) w = 4971 a = 0.4971