c7-3 (779517), страница 3
Текст из файла (страница 3)
Here,Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use.
Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).if (n != nold) {If n has changed, then compute useful quantien=n;ties.oldg=gammln(en+1.0);nold=n;} if (p != pold) {If p has changed, then compute useful quantipc=1.0-p;ties.plog=log(p);pclog=log(pc);pold=p;}sq=sqrt(2.0*am*pc);The following code should by now seem familiar:do {rejection method with a Lorentzian compardo {ison function.angle=PI*ran1(idum);y=tan(angle);em=sq*y+am;} while (em < 0.0 || em >= (en+1.0));Reject.em=floor(em);Trick for integer-valued distribution.t=1.2*sq*(1.0+y*y)*exp(oldg-gammln(em+1.0)-gammln(en-em+1.0)+em*plog+(en-em)*pclog);} while (ran1(idum) > t);Reject.
This happens about 1.5 times per devibnl=em;ate, on average..















