ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:164.08KB ,
资源ID:5213528      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5213528.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(四种分布 随机数拟合C+MATLAB.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

四种分布 随机数拟合C+MATLAB.docx

1、四种分布 随机数拟合C+MATLAB四种函数的拟合1正态分布#include/#include iomanip.h#include iomanip#include#include using namespace std;const int A=2045;const int C=1;const int M=1048576;/2的20次方double junyun(double a,double b,long int *seed)/采取的方法是混合同余法其中A,C,M都是自定义的常数 double t; *seed=A*(*seed)+C; *seed=(*seed)%M; t=(*seed)/(

2、double)M; t=a+(b-a)*t; return t;double gauss(double mean,double sigma,long int *s) int i; double x,y; for(x=0,i=0;i12;i+) x+=junyun(0.0,1.0,s); x=x-6.0; y=mean+x*sigma; return y;int main() int i,j,num; double x, mean,sigma; long int s; cout输入均值和方差的值meansigma; cout输入随机种子:s; cout输入生成随机数个数:num; ofstrea

3、m cout(zhengtai.txt); for(i=0;inum;i+) x=gauss(mean,sigma,&s); coutx ; cout ; return 0;运行程序:正态分布拟合图2均匀分布#include #include #include #include #include #include /#include graphics.hfloat a,b,c;int n,type;float nextGaussian(float a,float b) float v0,v1, v2, s; float nextNextGaussian; /int haveNextNextGa

4、ussian=0; do do v1 = 2 * (float)rand()/RAND_MAX)-1; / between -1.0 and 1.0 v2 = 2 * (float)rand()/RAND_MAX)-1; / between -1.0 and 1.0 s = v1 * v1 + v2 * v2; while (s = 1 | s = 0); float multiplier = float(sqrt(-2*log(s)/s); nextNextGaussian = v2 * multiplier; /haveNextNextGaussian = 1;v0=v1 * multip

5、lier; /均值为0,方差为1的标准正态分布 while(s = 1 | s = 0); return v0*b+a; /产生均值为a,方差为b的随机信号 float AverageRandom(float min,float max) float c1; c1=(float)rand()/RAND_MAX)*(max-min)+min; return c1;float sl(int n,int type,float a,float b) float a1,b1; a1=a;b1=b; if(type=0) c=AverageRandom(a1,b1); /产生均匀分布U(a,b) retu

6、rn c; else if(type=1) c=nextGaussian(a1,b1); /产生高斯分布N(a,b) return c; void main() int det;int *count;float before,next;float *xplot; float *s; FILE *outfile; srand(time(0); couttype; if(type=1) coutab; else coutab; coutn; s=new floatn; outfile = fopen(output.txt,w); for(int i=0;in;i+) c=sl(n,type,a,b

7、); fprintf(outfile,%f ,c); si=c; coutdet; count=new intdet; xplot=new floatdet;FILE *outfile1;FILE *outfile2;outfile1 = fopen(count.txt,w);outfile2 = fopen(xplot.txt,w);if(type=0) /如果是均匀分布的话before=a;next=a+(b-a)/det; for(int k=0;kdet;k+) countk=0; for(int j=0;jbefore&sjnext) countk=countk+1; xplotk=

8、(before+next)/2; before=before+(b-a)/det; next=next+(b-a)/det; else/如果是高斯分布的话 a=a-3*b; b=a+6*b; before=a; next=a+(b-a)/det; for(int k=0;kdet;k+) countk=0; for(int j=0;jbefore&sjnext) countk=countk+1; xplotk=(before+next)/2; before=before+(b-a)/det; next=next+(b-a)/det; 运行程序:均匀分布数据直方图3泊松分布#include #i

9、nclude #include #include #include double U_Random(); / 均匀随机数0到1int possion(int Lambda); / 泊松分布随机数 main()double u; float a; int Lambda; / 可以改为需要的目标平均值int i;int n;float *s;FILE *outfile;printf(Lambda=n);scanf(%d,&Lambda);srand( (unsigned)time( NULL ) ); / 种子u = U_Random();printf(n=n);scanf(%d,&n);s=ne

10、w floatn;outfile = fopen(output.txt,w);for (i=0;i=l)u = U_Random();p *= u;k+;return k-1;double U_Random() /* 0 to 1 rd */ double f; f = (double)(rand() % 1001); return f/1000.0;运行程序:泊松分布拟合图4指数分布#include/#include iomanip.h#include iomanip#include#include using namespace std;const int A=2045;const int

11、 C=1;const int M=1048576;/2的20次方double junyun(double a,double b,long int *seed)/采取的方法是混合同余法其中D,C,M都是自定义的常数 double t; *seed=A*(*seed)+C; *seed=(*seed)%M; t=(*seed)/(double)M; t=a+(b-a)*t; return t;double exponent(double beta,long int *s) double u,x; u=junyun(0.0,1.0,s); x=-beta*log(u); return x;int main() int i,j,num; double x,beta; long int s; cout输入均值:beta; cout输入随机种子:s; cout输入生成随机数个数:num; ofstream cout(zhishu.txt); for(i=0;inum;i+) x=exponent(beta,&s); coutx ; return 0;运行程序:指数分布直方图指数分布曲线图

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1