% slot_machine.m generates several outcomes of wealth while playing a hypothetical slot machine R=[0.92 0 0 0 0 0 0 0 0 0 0 0 0.04 0.04]; N=50; % number of quarters you begin with T=100; % number of times to play, if you have the money t=0:T; % time indices, t(1)=0, t(2)=1, ... w=zeros(1,T+1); sum(R.*[-1:(length(R)-2)]) for i=1:6, subplot(6,1,i); w(1)=N; % 1st value, not time 1! for i=1:T, if w(i)>0, w(i+1) = w(i) + rando(R) - 2; else w(i+1)=0; end end plot(t,w,'o'); axis([0 T 0 N*1.8]); end subplot(6,1,1); title('Wealth over time playing the slot machine'); subplot(6,1,6); xlabel('Time');