正在加载图片...
146 Chapter 4. Integration of Functions Similarly, #include <math.h> #define FUNC(x)(2.0*(x)*(*funk)(bb-(x)*(x))) float midsqu(float (*funk)(float),float aa,float bb,int n) This routine is an exact replacement for midpnt,except that it allows for an inverse square-root singularity in the integrand at the upper limit bb. float x,tnm,sum,del,ddel,a,b; static float s; int it,ji 83g b=sqrt(bb-aa); a=0.0; granted for 18881892 1f(n=1)[ The rest of the routine is exactly like midpnt and is omitted. 1800 One last example should suffice to show how these formulas are derived in from NUMERICAL RECIPES IN general.Suppose the upper limit of integration is infinite,and the integrand falls off exponentially.Then we want a change of variable that maps e-dr into()dt(with (Nort server the sign chosen to keep the upper limit of the new variable larger than the lower limit).Doing the integration gives by inspection America computer, e University Press. THE ART t=e-z or x=-logt (4.4.7) 9 Programs so that dt f(x)dx= f(-logt) (4.4.8) t=0 The user-transparent implementation would be #include <math.h> #define FUNC(x)((*funk)(-log(x))/(x)) float midexp(float (*funk)(float),float aa,float bb,int n) This routine is an exact replacement for midpnt,except that bb is assumed to be infinite ga之 19881982 OF SCIENTIFIC COMPUTING(ISBN Numerical Recipes 10-621 43108 (value passed not actually used).It is assumed that the function funk decreases exponentially rapidly at infinity. t (outside float x,tnm,sum,del,ddel,a,b; static float s; Software. int it,ji Amer b=exp(-aa); a=0.0; if(n==1){ The rest of the routine is exactly like midpnt and is omitted. CITED REFERENCES AND FURTHER READING: Acton,F.S.1970,Numerica/Methods That Work;1990,corrected edition (Washington:Mathe- matical Association of America),Chapter 4.146 Chapter 4. Integration of Functions 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). Similarly, #include <math.h> #define FUNC(x) (2.0*(x)*(*funk)(bb-(x)*(x))) float midsqu(float (*funk)(float), float aa, float bb, int n) This routine is an exact replacement for midpnt, except that it allows for an inverse square-root singularity in the integrand at the upper limit bb. { float x,tnm,sum,del,ddel,a,b; static float s; int it,j; b=sqrt(bb-aa); a=0.0; if (n == 1) { The rest of the routine is exactly like midpnt and is omitted. One last example should suffice to show how these formulas are derived in general. Suppose the upper limit of integration is infinite, and the integrand falls off exponentially. Then we want a change of variable that maps e −xdx into (±)dt (with the sign chosen to keep the upper limit of the new variable larger than the lower limit). Doing the integration gives by inspection t = e−x or x = − log t (4.4.7) so that  x=∞ x=a f(x)dx =  t=e−a t=0 f(− log t) dt t (4.4.8) The user-transparent implementation would be #include <math.h> #define FUNC(x) ((*funk)(-log(x))/(x)) float midexp(float (*funk)(float), float aa, float bb, int n) This routine is an exact replacement for midpnt, except that bb is assumed to be infinite (value passed not actually used). It is assumed that the function funk decreases exponentially rapidly at infinity. { float x,tnm,sum,del,ddel,a,b; static float s; int it,j; b=exp(-aa); a=0.0; if (n == 1) { The rest of the routine is exactly like midpnt and is omitted. CITED REFERENCES AND FURTHER READING: Acton, F.S. 1970, Numerical Methods That Work; 1990, corrected edition (Washington: Mathe￾matical Association of America), Chapter 4
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有