write a programe to generate n values from the probability mass function p1=1/3 p2=2/3n=100,1000,10000 and determine the proportion of values that are equal to 1应该怎么编程?
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 06:33:40
write a programe to generate n values from the probability mass function p1=1/3 p2=2/3n=100,1000,10000 and determine the proportion of values that are equal to 1应该怎么编程?
write a programe to generate n values from the probability mass function p1=1/3 p2=2/3
n=100,1000,10000 and determine the proportion of values that are equal to 1
应该怎么编程?
write a programe to generate n values from the probability mass function p1=1/3 p2=2/3n=100,1000,10000 and determine the proportion of values that are equal to 1应该怎么编程?
function [proportion]=kittyfang(n)
k=0;
for i=1:n
data=rand();
if data>1/3
k=k+1;
end
end
proportion=k/n;
以上就是MATLAB的M-文件.
不懂。。。。lz可以去比较专业的网站问问,高手在民间~
#include
#include
#include
int k,i,n;
float data,ans;
void main()
{
printf("Please enter a positive integer 'n':\n");
scanf("%d",&n);
全部展开
#include
#include
#include
int k,i,n;
float data,ans;
void main()
{
printf("Please enter a positive integer 'n':\n");
scanf("%d",&n);
srand(time(NULL));
for(i=0;i
data=rand()/(float)RAND_MAX;
if(data>(float)1/3)
k++;
}
ans=(float)k/n;
printf("The proportion of values that are equal to 1 is %f",ans);
}
收起