P***a 发帖数: 9 | 1 Sorry now I believe the variance is 155, and the expectation
is still 12.
I guess this is one of non's homework, right?
*********************************************
Let D be the random variable denoting the days the prisoner
in the cell, and T the random variable denoting the times
the prisoner selecting doors other than Door3.
The answer is E[D]=12 and var[D]=155.
E[D]=E[E[D|T]]
=Sum[ E[D|T=t]*0.8^t*0.2, {t,0,infinity}]
var[D]=E[var[D|T]]+var[E[D|T]]
=Sum[ var[D|T=t]*0.8^t*0.2, {t,0,infinity}] | d*z 发帖数: 150 | 2 It seems (12,155)
#include
#include
#include
#define MAX_COUNT 1000000
void main()
{
int days;
int i;
double sum,var;
srand(time(NULL));
sum=0;var=0;
for(i=0;i
{
days=0;
do
{
int r=rand()%10;
if(r<5)
{
days+=2;
}
else if(r<8)
{
days+=4;
}
else
{
days++;
break;
}
}while(1);
sum+=days;
var+=days*days;
}
sum/=MAX_COUNT;
var/=MAX_COUNT;
var-=sum*sum;
printf("Mean is %f,and Var is %f\n",sum,var);
}
【在 P***a 的大作中提到】 : Sorry now I believe the variance is 155, and the expectation : is still 12. : I guess this is one of non's homework, right? : ********************************************* : Let D be the random variable denoting the days the prisoner : in the cell, and T the random variable denoting the times : the prisoner selecting doors other than Door3. : The answer is E[D]=12 and var[D]=155. : E[D]=E[E[D|T]] : =Sum[ E[D|T=t]*0.8^t*0.2, {t,0,infinity}]
|
|