Home > sp > slot_machine.m

slot_machine

PURPOSE ^

slot_machine.m generates several outcomes of wealth while playing a hypothetical slot machine

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 slot_machine.m generates several outcomes of wealth while playing a hypothetical slot machine

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % slot_machine.m generates several outcomes of wealth while playing a hypothetical slot machine
0002       
0003 R=[0.92 0 0 0 0 0 0 0 0 0 0 0 0.04 0.04];
0004 N=50;        % number of quarters you begin with
0005 T=100;       % number of times to play, if you have the money
0006 
0007 t=0:T;       % time indices, t(1)=0, t(2)=1, ...
0008 w=zeros(1,T+1);
0009 
0010 sum(R.*[-1:(length(R)-2)])
0011 
0012 for i=1:6,
0013 
0014 subplot(6,1,i);
0015 
0016 w(1)=N;     % 1st value, not time 1!
0017 for i=1:T,
0018    if w(i)>0,
0019      w(i+1) = w(i) + rando(R) - 2;
0020    else
0021      w(i+1)=0;
0022    end
0023 end
0024 plot(t,w,'o');
0025 axis([0 T 0 N*1.8]);
0026 end
0027 
0028 subplot(6,1,1);
0029 title('Wealth over time playing the slot machine');
0030 
0031 subplot(6,1,6);
0032 xlabel('Time');

Generated on Mon 17-Mar-2008 10:33:42 by m2html © 2003