正在加载图片...
234 Chapter 6.Special Functions ans=(ans1/ans2)+0.636619772*(bessj1(x)*1og(x)-1.0/x); else Fitting function (6.5.10). z=8.0/x; y=z*z; xx=x-2.356194491: ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019a-6))); ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2); return ans; 83 鱼 19881992 We now turn to the second task,namely how to use the recurrence formulas (6.5.6)and(6.5.7)to get the Bessel functions n(x)and Yn(z)for n 2.The latter of these is straightforward,since its upward recurrence is always stable: from NUMERICAL RECIPESI float bessy(int n,float x) Returns the Bessel function Yn(x)for positive x and n 2. float bessy0(float x); float bessy1(float x); (North America 州bMe se to make one paper University Press. THE void nrerror(char error_text []) int ji ART float by,bym,byp,tox; if (n 2)nrerror("Index n less than 2 in bessy"); Programs tox=2.0/x; by=bessy1(x); Starting values for the recurrence. bym=bessy0(x); for (j=1;j<n;j++){ Recurrence (6.5.7). byp=j*tox*by-bym; to dir bym=by; by=byp; 1988199200 OF SCIENTIFIC COMPUTING(ISBN return by; v@cam 10-:6211 The cost of this algorithm is the call to bessy1 and bessyo(which generate a call to each of bessj1 and bessjo),plus O(n)operations in the recurrence. Numerical Recipes 43108 As for.().things are a bit more complicated.We can start the recurrence upward on n from.Jo and/1.but it will remain stable only while n does not exceed z.This is,however,just fine for calls with large z and small n,a case which (outside occurs frequently in practice. North Software. The harder case to provide for is that with x<n.The best thing to do here is to use Miller's algorithm(see discussion preceding equation 5.5.16),applying the recurrence dowmard from some arbitrary starting value and making use of the upward-unstable nature of the recurrence to put us onto the correct solution.When machine we finally arrive atJo orJ we are able to normalize the solution with the sum (5.5.16)accumulated along the way. The only subtlety is in deciding at how large an n we need start the downward recurrence so as to obtain a desired accuracy by the time we reach the n that we really want.If you play with the asymptotic forms(6.5.3)and(6.5.5),you should be able to convince yourself that the answer is to start larger than the desired n by234 Chapter 6. Special 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). ans=(ans1/ans2)+0.636619772*(bessj1(x)*log(x)-1.0/x); } else { Fitting function (6.5.10). z=8.0/x; y=z*z; xx=x-2.356194491; ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2); } return ans; } We now turn to the second task, namely how to use the recurrence formulas (6.5.6) and (6.5.7) to get the Bessel functions J n(x) and Yn(x) for n ≥ 2. The latter of these is straightforward, since its upward recurrence is always stable: float bessy(int n, float x) Returns the Bessel function Yn(x) for positive x and n ≥ 2. { float bessy0(float x); float bessy1(float x); void nrerror(char error_text[]); int j; float by,bym,byp,tox; if (n < 2) nrerror("Index n less than 2 in bessy"); tox=2.0/x; by=bessy1(x); Starting values for the recurrence. bym=bessy0(x); for (j=1;j<n;j++) { Recurrence (6.5.7). byp=j*tox*by-bym; bym=by; by=byp; } return by; } The cost of this algorithm is the call to bessy1 and bessy0 (which generate a call to each of bessj1 and bessj0), plus O(n) operations in the recurrence. As for Jn(x), things are a bit more complicated. We can start the recurrence upward on n from J0 and J1, but it will remain stable only while n does not exceed x. This is, however, just fine for calls with large x and small n, a case which occurs frequently in practice. The harder case to provide for is that with x<n. The best thing to do here is to use Miller’s algorithm (see discussion preceding equation 5.5.16), applying the recurrence downward from some arbitrary starting value and making use of the upward-unstable nature of the recurrence to put us onto the correct solution. When we finally arrive at J0 or J1 we are able to normalize the solution with the sum (5.5.16) accumulated along the way. The only subtlety is in deciding at how large an n we need start the downward recurrence so as to obtain a desired accuracy by the time we reach the n that we really want. If you play with the asymptotic forms (6.5.3) and (6.5.5), you should be able to convince yourself that the answer is to start larger than the desired n by
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有