正在加载图片...
714 Chapter 16.Integration of Ordinary Differential Equations dv=vector(1,nvar); for(1=1;1<=nvar;i++){ Load starting values. v[i]-vstart[i]; y[i][1]=v[1]; 2 xx[1]=x1; x=x1; h=(x2-x1)/nstep; for (k=1;k<=nstep;k++){ Take nstep steps. (*derivs)(x,v,dv); rk4(v,dv,nvar,x,h,vout,derivs); if ((float)(x+h)==x)nrerror("Step size too small in routine rkdumb"); X+=h; xx[0k+1]=x; Store intermediate steps. for (i=1;i<=nvar;i++){ v[i]-vout[i]: y[i][k+1]=v[i]; 2 2 令 1-800 NUMERI ICAL free_vector(dv,1,nvar); free_vector(vout,1,nvar); free_vector(v,1,nvar); RECIPES I (North America computer, Press. CITED REFERENCES AND FURTHER READING: Abramowitz,M.,and Stegun,I.A.1964,Handbook of Mathematical Functions,Applied Mathe- matics Series,Volume 55 (Washington:National Bureau of Standards;reprinted 1968 by 9 Programs Dover Publications,New York),825.5.[1] Gear,C.W.1971,Numerical Initial Value Problems in Ordinary Differential Equations(Englewood 、核 OF SCIENTIFIC Cliffs,NJ:Prentice-Hall),Chapter 2.[2] Shampine,L.F.,and Watts,H.A.1977,in Mathematica/Software /l,J.R.Rice,ed.(New York:Aca- 61 demic Press),pp.257-275:1979,Applied Mathematics and Computation,vol.5,pp.93- 121.[3] Rice,J.R.1983,Numerical Methods,Software,and Analysis (New York:McGraw-Hill),89.2. Numerica 10.621 16.2 Adaptive Stepsize Control for Runge-Kutta 431 Recipes A good ODE integrator should exert some adaptive control over its own progress, (outside making frequent changes in its stepsize.Usually the purpose of this adaptive stepsize 首 control is to achieve some predetermined accuracy in the solution with minimum computational effort.Many small steps should tiptoe through treacherous terrain. while a few great strides should speed through smooth uninteresting countryside. The resulting gains in efficiency are not mere tens of percents or factors of two; they can sometimes be factors of ten,a hundred,or more.Sometimes accuracy may be demanded not directly in the solution itself,but in some related conserved quantity that can be monitored. Implementation of adaptive stepsize control requires that the stepping algorithm signal information about its performance,most important,an estimate of its truncation error.In this section we will learn how such information can be obtained.Obviously.714 Chapter 16. Integration of Ordinary Differential Equations 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). dv=vector(1,nvar); for (i=1;i<=nvar;i++) { Load starting values. v[i]=vstart[i]; y[i][1]=v[i]; } xx[1]=x1; x=x1; h=(x2-x1)/nstep; for (k=1;k<=nstep;k++) { Take nstep steps. (*derivs)(x,v,dv); rk4(v,dv,nvar,x,h,vout,derivs); if ((float)(x+h) == x) nrerror("Step size too small in routine rkdumb"); x += h; xx[k+1]=x; Store intermediate steps. for (i=1;i<=nvar;i++) { v[i]=vout[i]; y[i][k+1]=v[i]; } } free_vector(dv,1,nvar); free_vector(vout,1,nvar); free_vector(v,1,nvar); } CITED REFERENCES AND FURTHER READING: Abramowitz, M., and Stegun, I.A. 1964, Handbook of Mathematical Functions, Applied Mathe￾matics Series, Volume 55 (Washington: National Bureau of Standards; reprinted 1968 by Dover Publications, New York), §25.5. [1] Gear, C.W. 1971, Numerical Initial Value Problems in Ordinary Differential Equations (Englewood Cliffs, NJ: Prentice-Hall), Chapter 2. [2] Shampine, L.F., and Watts, H.A. 1977, in Mathematical Software III, J.R. Rice, ed. (New York: Aca￾demic Press), pp. 257–275; 1979, Applied Mathematics and Computation, vol. 5, pp. 93– 121. [3] Rice, J.R. 1983, Numerical Methods, Software, and Analysis (New York: McGraw-Hill), §9.2. 16.2 Adaptive Stepsize Control for Runge-Kutta A good ODE integrator should exert some adaptive control over its own progress, making frequent changes in its stepsize. Usually the purpose of this adaptive stepsize control is to achieve some predetermined accuracy in the solution with minimum computational effort. Many small steps should tiptoe through treacherous terrain, while a few great strides should speed through smooth uninteresting countryside. The resulting gains in efficiency are not mere tens of percents or factors of two; they can sometimes be factors of ten, a hundred, or more. Sometimes accuracy may be demanded not directly in the solution itself, but in some related conserved quantity that can be monitored. Implementation of adaptive stepsize control requires that the stepping algorithm signal information about its performance,most important, an estimate of its truncation error. In this section we will learn how such information can be obtained. Obviously
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有