Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kaye

Posts: 5
Registered: 12/10/12
Matlab betting on a biased coin
Posted: Feb 11, 2013 7:25 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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)')



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.