资源描述:
《通信建模作业程序集锦.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.正态分布:#include#include#include#include#includeusingnamespacestd;#definepi3.//Generatearandonnumberfollowedbyuniformdistributionbetweentheinteval[min,max]templateTrand(Tmin,Tmax){returnmin+(max-min)*rand()/(RAND_
2、MAX+1.0);}//calculatethenormaldensitydistributionvaluesdoublenormal(doublex,doublemiu,doublesigma){return1.0/sqrt(2*pi)/sigma*exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));}//Generateadistributedrandomoutputnumberdoublerandn(doublemiu,doublesigma,doublemin,doublemax){double
3、x,y,dScope;do{x=rand(min,max);y=normal(x,miu,sigma);dScope=rand(0.0,normal(miu,miu,sigma));}while(dScope>y);returnx;}//Generate10000distributedrandomoutputnumbersandputintoatextcalled"123"intmain(intargc,char*argv[]){doublemin,max,miu,sigma;srand((unsigned)time(NULL))
4、;cin>>min>>max>>miu>>sigma;ofstreamoutfile("123.txt");for(inti=0;i<10000;i++){outfile<#include#include#include#definepi3.//generatetherandomnumbersbetweentheinterval[0,1]double
5、randn(){doublef;f=(double)(rand()%1001);//[0,1000]returnf/1000.0;//[0,1]}//calculatetheRayleighdensityfunctionvaluesbyusingthefollowinggeneratedrandomnumbersdoubleruili(doublesigma){Returnrandn()/(sigma*sigma)*exp(-randn()*randn()/(2*sigma*sigma));}//Themainfunctionca
6、ngenerate10000distributedrandomoutputnumberswhichareputintoatextcalled”321”intmain(void){doublesigma;srand((unsigned)time(NULL));printf("inputsigma:");scanf("%lf",&sigma);for(inti=0;i<10000;i++){FILE*fp;fp=fopen("321.txt","a+");fprintf(fp,"%lf,",ruili(sigma));printf
7、("%lf",randn());fclose(fp);}return0;]3.泊松分布:#include#include#include#include//GeneratetherandomnumberslongPossion(doubleu){doubleP,U;longN;u=exp(-u);P=1;N=0;while(1){U=(double)rand()/RAND_MAX;P=P*U;if(P<=u)break;N++;}returnN;}//Gene
8、rate10000distributedrandomoutputnumberswhichareputintoatextcalled”312”voidmain(){intk;doublelamda;scanf("%lf",&lamda);FILE*f