- #1
jk22
- 729
- 24
Hello I'm trying to solve the following problem : a coin is tossed with probability 1/2 of giving head but if it lands head the probability of head rise to .9. If it gives tail again or if the number of head is bigger equal 5 in a row then it fails down to .5.
I wrote a code running for 100000000 trials and found the probability of head
were near .703
I would like to calculate this probability exactly I started with an empirical equation $$p (h)=\underbrace {(.9-(.9-.5)e^{-5a})}_{p_1-(p_1-p_0)e^{-an}}p (h)+p_0*p (t) $$ ??*
With $$p (h)+p (t)=1$$.
I don't understand how to find the exact formula * for the probabilities given the problem since the parameter a above should be fitted with numerical results.
I wrote a code running for 100000000 trials and found the probability of head
C:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
double rnd()
{
int maxv=1<<24;
int val=rand()%maxv;
return((double)val/(double)maxv);
}
int main(void)
{
int iter=100000000;
int numpile=0;
double p=.5;
int pileserie=0;
srand(time(0));
for(int i=0;i<iter;i++)
{
if(rnd()<p) // choose head
{
numpile++;
pileserie++;
if(pileserie>=5)
p=.5;
else
p=.9;
}
else // else tail
{
pileserie=0;
p=.5;
}
}
printf("%lf\n",(double)numpile/(double)iter);
}
I would like to calculate this probability exactly I started with an empirical equation $$p (h)=\underbrace {(.9-(.9-.5)e^{-5a})}_{p_1-(p_1-p_0)e^{-an}}p (h)+p_0*p (t) $$ ??*
With $$p (h)+p (t)=1$$.
I don't understand how to find the exact formula * for the probabilities given the problem since the parameter a above should be fitted with numerical results.
Last edited: