用c语言生成随机数报告.

用c语言生成随机数报告.

ID:17631850

大小:585.00 KB

页数:12页

时间:2018-09-04

用c语言生成随机数报告._第1页
用c语言生成随机数报告._第2页
用c语言生成随机数报告._第3页
用c语言生成随机数报告._第4页
用c语言生成随机数报告._第5页
资源描述:

《用c语言生成随机数报告.》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、Name:陈启武Studentnumber:2014200557Profession:MicroelectronicsTask1:GeneraterandomvariatesforGaussiandistriubutionanddrawthecorrespondingPDFs1、Theprincipal:a)Inprobabilitytheory,thenormal(orGaussian)distributionisaverycommonlyoccurringcontinuousprobabilitydistribution.Theprobabilityde

2、nsityfunctionofthenormaldistributionisTheparameterinthisdefinitionisthemeanorexpectationofthedistribution(andalsoitsmedianandmode).Theparameterisitsstandarddeviation;itsvarianceistherefore.ArandomvariablewithaGaussiandistributionissaidtobenormallydistributedandiscalledanormaldeviat

3、e.b)Themethodofgeneratingrandomnumbersistousethe“rand()”functiontogeneratearandomnumberinC++programfirstly,thenthegeneratedrandomnumberismappedtotherequiredrange.Inthetext,Igenerated10,000randomnumbersfollowedbyuniformdistributionbetweentheinterval[-10,10].c)Wecanusethegeneratedran

4、domnumberstocalculatedensityfunctionvalues,thesevaluesaretherequiredrandomnumbersfornormaldistributon.Inthetest,Idefined“normal()”functiontogenerate10000idensityfunctionvalueswhichhavebeenputintoatextcalled”123”.d)Finally,wemustdrawthecorrespondingPDFstotestandverifyprobabilitydens

5、ityfunctionvalueswithMATLAB.Inthetest,IIputtheprogrammeddatasinto500groupsandgetthedifferenthistogramsfornormal(0,1),(0,4.26),(-2.5,1).Here’sthecommandsofmatlabIhaveusedinthetest.m=load('F:textormal123.txt')hist(m,500)Title(‘N(miu,sigma)’)2、TheC++sourceprogram:#include#

6、include#include#include#includeusingnamespacestd;#definepi3.1415926//Generatearandonnumberfollowedbyuniformdistributionbetweentheinteval[min,max]templateTrand(Tmin,Tmax){returnmin+(max-min)*rand()/(RAND_MAX+1.0);}//calculatethenormald

7、ensitydistributionvaluesdoublenormal(doublex,doublemiu,doublesigma){return1.0/sqrt(2*pi)/sigma*exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));}//Generateadistributedrandomoutputnumberdoublerandn(doublemiu,doublesigma,doublemin,doublemax){doublex,y,dScope;do{x=rand(min,max);y=normal(x,miu,

8、sigma);dScope=rand(0.0,nor

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。