c數(shù)值算法程序大全c17-2_第1頁
c數(shù)值算法程序大全c17-2_第2頁
c數(shù)值算法程序大全c17-2_第3頁
c數(shù)值算法程序大全c17-2_第4頁
c數(shù)值算法程序大全c17-2_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、760Chapter 17. Two Point Boundary Value ProblemsSample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5Copyright (C 1988-1992 by Cambridge University Press. P rograms Copyright (C 1988-1992 by Numerical Recipes Software. Permission is granted for internet users t

2、o make one paper copy for their own personal use. Further reproduction, or any copying of machine-readable files (including this one to any server c omputer, is strictly prohibited. To order Numerical Recipes books, d iskettes, or CDROMsvisit website or call 1-800-872-7423 (North America only, o r s

3、end email to tradecup.cam.ac.uk (outside North America.17.2Shooting to a Fitting PointThe shooting method described in §17.1tacitly assumed that the “shots” would be able to traverse the entire domain of integration, even at the early stages of convergence to a correct solution. In some problem

4、s it can happen that, for very wrong starting conditions, an initial solution cant even get from x 1to x 2without encountering some incalculable, or catastrophic, result. For example, the argument of a square root might go negative, causing the numerical code to crash. Simple shooting would be stymi

5、ed.A different, but related, case is where the endpoints are both singular points of the set of ODEs. One frequently needs to use special methods to integrate near the singular points, analytic asymptotic expansions, for example. In such cases it is feasible to integrate in the direction away from a

6、 singular point, using the special method to get through the rst little bit and then reading off “initial” values for further numerical integration. However it is usually not feasible to integrate into a singular point, if only because one has not usually expended the same analytic effort to obtain

7、expansions of “wrong” solutions near the singular point (thosenot satisfying the desired boundary condition.The solution to the above mentioned difculties is shooting to a tting point . Instead of integrating from x 1to x 2, we integrate rst from x 1to some point x f that is between x 1and x 2; and

8、second from x 2(inthe opposite direction to x f .If (asbefore the number of boundary conditions imposed at x 1is n 1, and the number imposed at x 2is n 2, then there are n 2freely speciable starting values at x 1and n 1freely speciable starting values at x 2. (Ifyou are confused by this, go back to

9、§17.1. We can therefore dene an n 2-vector V (1of starting parameters at x 1, and a prescription load1(x1,v1,yfor mapping V (1into a y that satises the boundary conditions at x 1,Likewise we can dene an n 1-vector V (2of starting parameters at x 2, and a prescription load2(x2,v2,yfor mapping V

10、(2into a y that satises the boundary conditions at x 2,We thus have a total of N freely adjustable parameters in the combination of V (1and V (2. The N conditions that must be satised are that there be agreement in N components of y at x f between the values obtained integrating from one side and fr

11、om the other,In some problems, the N matching conditions can be better described (physically,mathematically, or numerically by using N different functions F i , i =1. N , each possibly depending on the N components y i . In those cases, (17.2.3is replaced by17.2Shooting to a Fitting Point 761Sample

12、page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5Copyright (C 1988-1992 by Cambridge University Press. P rograms Copyright (C 1988-1992 by Numerical Recipes Software. Permission is granted for internet users to make one paper copy for their own personal use. Furth

13、er reproduction, or any copying of machine-readable files (including this one to any server c omputer, is strictly prohibited. To order Numerical Recipes books, d iskettes, or CDROMsvisit website or call 1-800-872-7423 (North America only, o r send email to tradecup.cam.ac.uk (outside North America.

14、In the program below, the user-supplied function score(xf,y,fis supposed to map an input N -vector y into an output N -vector F . In most cases, you can dummy this function as the identity mapping.Shooting to a tting point uses globally convergent Newton-Raphson exactly as in §17.1. Comparing c

15、losely with the routine shoot of the previous section, you should have no difculty in understanding the following routine shootf . The main differences in use are that you have to supply both load1and load2. Also, in the calling program you must supply initial guesses for v11.n2and v21.n1. Once agai

16、n a sample program illustrating shooting to a tting point is given in §17.4. #include"nrutil.h"extern int nn2,nvar; Variables that you must dene and set in your main pro-gram.extern float x1,x2,xf; int kmax,kount; Communicates with odeint .float *xp,*yp,dxsav;void shootf(intn, float v

17、,float fRoutine for use with newt to solve a two point boundary value problem for nvar coupled ODEs by shooting from x1and x2to a tting point xf . Initial values for the nvar ODEs atx1(x2are generated from the n2(n1coecients v1(v2, using the user-supplied routine load1(load2. The coecients v1and v2s

18、hould be stored in a single array v1.n1+n2in the main program by statements of the form v1=v;and v2=&vn2;. The input param-eter n =n1+n2=nvar . The routine integrates the ODEs to xf using the Runge-Kutta method with tolerance EPS , initial stepsize h1, and minimum stepsize hmin . At xf it calls

19、the user-supplied routine score to evaluate the nvar functions f1and f2that ought to match at xf . The dierences f are returned on output. newt uses a globally convergent Newtons method to adjust the values of v until the functions f are zero. The user-supplied routinederivs(x,y,dydxsupplies derivat

20、ive information to the ODE integrator (seeChapter 16.The rst set of global variables above receives its values from the main program so that shoot can have the syntax required for it to be the argument vecfunc of newt . Set nn2=n2in the main program.void derivs(floatx, float y,float dydx;void load1(

21、floatx1, float v1,float y;void load2(floatx2, float v2,float y;void odeint(floatystart,int nvar, float x1, float x2,float eps, float h1, float hmin, int *nok,int *nbad,void (*derivs(float,float ,float ,void (*rkqs(float,float ,int, float *,float, float,float ,float *,float *,void (*(float,float ,flo

22、at ;void rkqs(floaty,float dydx,int n, float *x,float htry, float eps, float yscal,float *hdid,float *hnext,void (*derivs(float,float ,float ;void score(floatxf, float y,float f;int i,nbad,nok;float h1,hmin=0.0,*f1,*f2,*y;f1=vector(1,nvar;f2=vector(1,nvar;y=vector(1,nvar;kmax=0;h1=(x2-x1/100.0;load1

23、(x1,v,y;Path from x1to xf with best trial values v1.odeint(y,nvar,x1,xf,EPS,h1,hmin,&nok,&nbad,derivs,rkqs;score(xf,y,f1;load2(x2,&vnn2,y;Path from x2to xf with best trial values v2.odeint(y,nvar,x2,xf,EPS,h1,hmin,&nok,&nbad,derivs,rkqs;score(xf,y,f2;762Chapter 17. Two Point Boun

24、dary Value ProblemsSample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5Copyright (C 1988-1992 by Cambridge University Press. P rograms Copyright (C 1988-1992 by Numerical Recipes Software. Permission is granted for internet users to make one paper copy for the

25、ir own personal use. Further reproduction, or any copying of machine-readable files (including this one to any server c omputer, is strictly prohibited. To order Numerical Recipes books, d iskettes, or CDROMsvisit website or call 1-800-872-7423 (North America only, o r send email to tradecup.cam.ac.

26、uk (outside North America.for (i=1;i<=n;i+fi=f1i-f2i;free_vector(y,1,nvar;free_vector(f2,1,nvar;free_vector(f1,1,nvar;There are boundary value problems where even shooting to a tting point fails the integration interval has to be partitioned by several tting points with the solution being matched

27、 at each such point. For more details see 1.CITED REFERENCES AND FURTHER READING:Acton, F .S. 1970, Numerical Methods That Work ; 1990, corrected edition (Washington:Mathe-matical Association of America.Keller, H.B. 1968, Numerical Methods for Two-Point Boundary-Value Problems (Waltham,MA:Blaisdell.

28、Stoer, J., and Bulirsch, R. 1980, Introduction to Numerical Analysis (NewYork:Springer-Verlag,§§7.3.57.3.6. 117.3Relaxation MethodsIn relaxation methods we replace ODEs by approximate nite-difference equations (FDEson a grid or mesh of points that spans the domain of interest. As a typical

29、 example, we could replace a general rst-order differential equationdywith an algebraic equation relating function values at two points k, k 1:y k y k 1 (x k x k 1 g 12(x k +x k 1 , 1The form of the FDE in (17.3.2illustrates the idea, but not uniquely:There are many ways to turn the ODE into an FDE.

30、 When the problem involves N coupled rst-order ODEs represented by FDEs on a mesh of M points, a solution consists of values for N dependent functions given at each of the M mesh points, or N ×M variables in all. The relaxation method determines the solution by starting with a guess and improvi

31、ng it, iteratively. As the iterations improve the solution, the result is said to relax to the true solution.While several iteration schemes are possible, for most problems our old standby, multi-dimensional Newtons method, works well. The method produces a matrix equation that must be solved, but the matrix takes a special, “block diagonal

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論