Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Matlab betting on a biased coin
Replies: 2   Last Post: Feb 11, 2013 10:34 AM

 Messages: [ Previous | Next ]
 Kaye Posts: 5 Registered: 12/10/12
Matlab betting on a biased coin
Posted: Feb 11, 2013 7:25 AM

I'm trying to run a simluation on a biased coin toss. At each toss i want to 'bet' a specific fraction of my current wealth on the coin toss, then run this for 100+ tosses and plot my wealth over these tosses. This is what i have so far but something in my for loop is not right. Can anyone help with this?
Thanks
K

>>Ntoss = 100;
Wealth(1)=100;
bet(1)=50;
for i=2:Ntoss
bet(i)=0.5*Wealth(i-1);
s = -bet(i)* ones(1, Ntoss);
u = rand(1, Ntoss);
h = find(u < 0.6); % finds where it was heads.
winnings = cumsum(s);
Wealth(i)=Wealth(i-1)+winnings(i);
end
plot(1:Ntoss, Wealth)
xlabel('Toss')
ylabel('S(n)')

Date Subject Author
2/11/13 Kaye
2/11/13 Curious
2/11/13 Curious