Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab betting on a biased coin
Date: Mon, 11 Feb 2013 15:34:17 +0000 (UTC)
Organization: Mitre Corp
Lines: 39
Message-ID: <kfb31p$ses$1@newscl01ah.mathworks.com>
References: <kfanvi$do5$1@newscl01ah.mathworks.com> <kfb27p$p8i$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1360596857 29148 172.30.248.35 (11 Feb 2013 15:34:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 11 Feb 2013 15:34:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2318
Xref: news.mathworks.com comp.soft-sys.matlab:788769

"someone" wrote in message <kfb27p$p8i$1@newscl01ah.mathworks.com>...
> "Kaye" wrote in message <kfanvi$do5$1@newscl01ah.mathworks.com>...
> > 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)')
> 
> Without knowing what the error message is (if any), I have two suggestions:
> 
> Change:
> s = -bet(i)* ones(1, Ntoss);  % matrix multiplication
> To:
> s = -bet(i).*ones(1, Ntoss);  % element-by-element multipl;ication
> 
> Change:
> Wealth(i)=Wealth(i-1)+winnings(i);  % What is the valuie of winning(i)?
> To:
> Wealth(i)=Wealth(i-1)+winnings;

After a little more looking, I suspect something is wrong with:
winnings = cumsum(s);

You are not using h for anything.  Perhaps you mean:
winnings = cumsum(h);