正在加载图片...
322 Chapter 7. Random Numbers for(;;){ fb=f2b=0.0; for (k=1;k<=npg;k++){ wgt=xjac; for (j=1;j<=ndim;j++){ xn=(kg[j]-ran2(&idum))*dxg+1.0; ia[j]=IMAX(IMIN((int)(xn),NDMX),1) if(1a[j]>1)[ xo=xi[i][ia[i]]-xi[j][ia[i]-1]; rc=xi[j][ia[j]-1]+(xn-ia[j])*xo; else read able files Per xo=xi[i][ia[i]]; rc=(xn-ia[j])*xo; x[j]=regn[j]+rc*dx[j]; granted for i wgt *xo*xnd; http://www.nr.com or call 1-800-872- (including this one) f=wgt*(*fx知)(x,gt); internet f2=f*f; fb +f; f2b+=f2; for (j=1;i<=ndim;++){ di[ia[j]][j]f; if (mds >=0)d[ia[j]][j]+f2; -7423(North America to any server computer,is strictly prohibited. tusers to make one paper 1988-1992 by Cambridge University Press.Programs from NUMERICAL RECIPES IN C: THE f2b=sqrt(f2b*npg); f2b=(f2b-fb)*(f2b+fb); if (f2b <0.0)f2b=TINY; only),or ti +fb; tsi +f2b; copy for their if (mds <0){ Use stratified sampling for (j=1;j<=ndim;j++)d[ia[j]][j]+f2b; for (k=ndim;k>=1;k--){ kg[k]%ngi if (++kg[k]!1)break; email to directcustsen if (k 1)break; ART OF SCIENTIFIC COMPUTING(ISBN 0-521- tsi *dv2g; Compute final results for this iteration. wgt=1.0/tsi; si +wgt*ti; schi +wgt*ti*ti; swgt +wgt; @cambridge.org To order Numerical Recipes books or personal use.Further reproduction,or 1988-1992 by Numerical Recipes *tgral=si/swgt; -431085 *chi2a=(schi-si*(*tgral))/(it-0.9999); 1f(*chi2a<0.0)*chi2a=0.0; *sd=sqrt(1.0/swgt); tsi=sqrt(tsi); if (nprn >0){ printf("%s %3d integral =%14.7g +/-%9.2g\n", (outside North America) Software. ying of iteration no.",it,ti,tsi); printf("%s integral =%14.7g+/-%9.2g chi**2/IT n %9.2g\n", all iterations:",*tgral,*sd,*chi2a); if (nprn){ for (j=1;i<=ndim;++){ printf("DATA FOR axis %2d\n",j); pr1ntf("%6s%13s%11s13s%11s%13s\n", "X","delta i","X","delta i","X","delta i"); for (i=1+nprn/2;i<=nd;i +nprn+2){ pr1ntf("%8.5f%12.4g%12.5f%12.4g%12.5f%12.4g\n", x1[j][i],di[i][j],x1[][i+1],322 Chapter 7. Random Numbers Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). } for (;;) { fb=f2b=0.0; for (k=1;k<=npg;k++) { wgt=xjac; for (j=1;j<=ndim;j++) { xn=(kg[j]-ran2(&idum))*dxg+1.0; ia[j]=IMAX(IMIN((int)(xn),NDMX),1); if (ia[j] > 1) { xo=xi[j][ia[j]]-xi[j][ia[j]-1]; rc=xi[j][ia[j]-1]+(xn-ia[j])*xo; } else { xo=xi[j][ia[j]]; rc=(xn-ia[j])*xo; } x[j]=regn[j]+rc*dx[j]; wgt *= xo*xnd; } f=wgt*(*fxn)(x,wgt); f2=f*f; fb += f; f2b += f2; for (j=1;j<=ndim;j++) { di[ia[j]][j] += f; if (mds >= 0) d[ia[j]][j] += f2; } } f2b=sqrt(f2b*npg); f2b=(f2b-fb)*(f2b+fb); if (f2b <= 0.0) f2b=TINY; ti += fb; tsi += f2b; if (mds < 0) { Use stratified sampling. for (j=1;j<=ndim;j++) d[ia[j]][j] += f2b; } for (k=ndim;k>=1;k--) { kg[k] %= ng; if (++kg[k] != 1) break; } if (k < 1) break; } tsi *= dv2g; Compute final results for this iteration. wgt=1.0/tsi; si += wgt*ti; schi += wgt*ti*ti; swgt += wgt; *tgral=si/swgt; *chi2a=(schi-si*(*tgral))/(it-0.9999); if (*chi2a < 0.0) *chi2a = 0.0; *sd=sqrt(1.0/swgt); tsi=sqrt(tsi); if (nprn >= 0) { printf("%s %3d : integral = %14.7g +/- %9.2g\n", " iteration no.",it,ti,tsi); printf("%s integral =%14.7g+/-%9.2g chi**2/IT n = %9.2g\n", " all iterations: ",*tgral,*sd,*chi2a); if (nprn) { for (j=1;j<=ndim;j++) { printf(" DATA FOR axis %2d\n",j); printf("%6s%13s%11s%13s%11s%13s\n", "X","delta i","X","delta i","X","delta i"); for (i=1+nprn/2;i<=nd;i += nprn+2) { printf("%8.5f%12.4g%12.5f%12.4g%12.5f%12.4g\n", xi[j][i],di[i][j],xi[j][i+1]
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有