Solving Differential Equations in R

Solving Differential Equations in R

Use R! Solving Differential Equations in R Bearbeitet von Karline Soetaert, Jeff Cash, Francesca Mazzia 1. Auflage 2012. Taschenbuch. xvi, 248 S. Paperback ISBN 978 3 642 28069 6 Format (B x L): 15,5 x 23,5 cm Gewicht: 409 g Weitere Fachgebiete > Mathematik > Stochastik > Mathematische Statistik Zu Inhaltsverzeichnis schnell und portofrei erhältlich bei Die Online-Fachbuchhandlung beck-shop.de ist spezialisiert auf Fachbücher, insbesondere Recht, Steuern und Wirtschaft. Im Sortiment finden Sie alle Medien (Bücher, Zeitschriften, CDs, eBooks, etc.) aller Verlage. Ergänzt wird das Programm durch Services wie Neuerscheinungsdienst oder Zusammenstellungen von Büchern zu Sonderpreisen. Der Shop führt mehr als 8 Millionen Produkte. Chapter 2 Initial Value Problems Abstract In the previous chapter we derived a simple finite difference method, namely the explicit Euler method, and we indicated how this can be analysed so that we can make statements concerning its stability and order of accuracy. If Euler’s method is used with constant time step h then it is convergent with an error of order O(h) for all sufficiently smooth problems. Thus, if we integrate from 0 to 1 with step h = 10−5, we will need to perform 105 function evaluations to complete the integration and obtain a solution with error O(h). To achieve extra accuracy using this method we could reduce the step size h. This is not in general efficient and in many cases it is preferable to use higher order methods rather than decreasing the step size with a lower order method to obtain higher accuracy. One of the main differences between Euler’s and higher order methods is that, whereas Euler’s method uses only information involving the value of y and its derivative (slope) at the start of the integration interval to advance to the next integration step, higher order methods use information at more than one point. There exist two important classes of higher order methods that we will describe here, namely Runge-Kutta methods and linear multistep methods. 2.1 Runge-Kutta Methods In this section we will consider the derivation of high order Runge-Kutta methods suitable for the numerical integration of first order systems of ODEs. 2.1.1 Explicit Runge-Kutta Formulae We first consider again the forward Euler method which we have claimed in the previous chapter to be of order 1. Recall that this method is given by: yn+1 = yn + hf(xn,yn), (2.1) K. Soetaert et al., Solving Differential Equations in R, Use R! 61, 15 DOI 10.1007/978-3-642-28070-2 2, © Springer-Verlag Berlin Heidelberg 2012 16 2 Initial Value Problems and its local truncation error is given by: LTE = y(xn+1) − yn − hf(xn,yn), (2.2) assuming that yn ≡ y(xn). To increase accuracy, one approach is to include extra function evaluations in the numerical procedure. Thus, in the case of Runge-Kutta methods, the derivatives at several points within the integration interval [xn,xn+1] are evaluated and used to advance the integration from xn to xn+1. Runge [34] considered whether it was possible to find high order methods for the numerical solution of (1.1), but it was Kutta [28] who first formulated the general form of a standard explicit Runge-Kutta method as: s yn+1 = yn + h ∑ b jk j j=1 i−1 ki = f (xn + cih,yn + h ∑ aijk j), i = 1,2,...,s (2.3) j=1 i−1 ci = ∑ aij, j=1 where s is the number of intermediate points (“stages”) and k j are the corresponding slopes. This formula gives an approximate solution at xn+1 = xn + h, by computing 1 s intermediate stages in the interval [xn,xn+1]. A great stride forward in the analysis of Runge-Kutta formulae was made by Butcher [9] who suggested writing these formulae in the so-called tableau form: 0 0 c2 a21 0 c3 a31 a32 0 . (2.4) . .. .. cs as1 as2 ··· as,s−1 0 b1 b2 ··· bs−1 bs This can be written in the more concise form c A (2.5) bT 1Notwithstanding these intermediate stages or steps, you should not be tempted to call a Runge- Kutta method a “multistep” method. This terminology is reserved for a totally different type of method (Sect. 2.2). 2.1 Runge-Kutta Methods 17 Since for the time being we are considering only explicit Runge-Kutta methods, the ki are defined only in terms of k1,...,ki−1, 2 ≤ i ≤ s, and consequently the matrix A is strictly lower triangular. Later on we will deal in more depth with implicit methods, for which A will have non-zero elements on, and/or above, the diagonal. We now define the order of a Runge-Kutta formula [21, p. 133]. Suppose we integrate from x0 to x1 = x0 + h using (2.3) and we denote the analytic solution at x1 by y(x0 + h) and the solution obtained at x1 using (2.3)byy1, then the Runge- Kutta method is said to have order p if, for sufficiently smooth problems (1.1) and h sufficiently small, p+1 ||y(x0 + h) − y1|| < Ch , (2.6) where C is a constant not depending on h. As shown in [21, p. 163], subject to certain smoothness assumptions, if the local error is bounded by Chp+1 then the global error will be bounded by Khp where, similarlytoabove,K is a constant not depending on h. 2.1.2 Deriving a Runge-Kutta Formula In order to be able to derive efficient Runge-Kutta methods several problems, such as high accuracy, stability, provision of continuous solutions, need to be addressed. 2.1.2.1 The Order Conditions One major problem is to determine the coefficients A, b and c in (2.5)insuchaway that the Runge-Kutta method has a certain order, preferably as high as possible, with as few stages, i.e. function evaluations, as possible. The problem of obtaining the so-called order relations was in the past a bit of a mine field because for example the equations to be solved for are nonlinear and there are more order relations if y is a vector than if y is a scalar. However this was solved by the work of Butcher [9], who derived the order relations for a system. For example, the conditions for Runge-Kutta methods to have order 1, 2 or 3 are respectively: order 1 : ∑bi = 1 (2.7) i order 2 : ∑bici = 1/2 (2.8) i 2 = / order 3 : ∑bici 1 3 (2.9) i ∑biaijc j = 1/6, (2.10) ij 18 2 Initial Value Problems where to obtain order 2, we need to satisfy (2.7)and(2.8), while to obtain order 3, we need to satisfy (2.7)–(2.10). Similar conditions exist for higher order methods (see also [21, p. 134] for a fourth order formula). However, the number of order conditions rapidly increases as the required order is increased. For example, to get an order 4 Runge-Kutta formula, eight simultaneous nonlinear algebraic equations need to be solved, while to obtain order 8, we need to solve 200 simultaneous algebraic equations. 2.1.2.2 Controlling the Error Another problem is to control the global error. Unfortunately this is usually not possible so, instead, we estimate and control the local truncation error (LTE). This is done by adapting the step size h in such a way that the estimate of the LTE is smaller than some preset value tol. The LTE itself is usually estimated using embedding.In this approach two different numerical solutions to the problem, which we denote here by yn+1 andy ˆn+1, are obtained with two different Runge-Kutta formulae, one of order p + 1 and one of order p respectively. Assuming that the O(hp+2) term in p+1 the LTE of yn+1 is negligible compared to the O(h ) term, we will accept the solution yn+1 if ||yˆn+1 − yn+1|| ≤ tol. (2.11) If the error estimate is larger than tol, the integration step h will be reduced until the accuracy condition is met [32]. Conversely, if the integration step h produces solutions whose local truncation error is estimated to be much smaller than the preset value, then the solution is accepted and the integration step h is increased. In practice a mixed absolute-relative error is used based on two tolerances atol and rtol, and we accept the solution if yˆn+1 − yn+1≤atol + rtolyn+1, (2.12) or |yˆn+1,i − yn+1,i|≤atoli + rtoli|yn+1,i|, (2.13) for all i, if a componentwise error control is considered. Here yn+1,i denotes the ith component of the vector yn+1. Note that this process, known as local extrapolation, is not entirely satisfactory since we attempt to control the error iny ˆn+1, yet accept the solution yn+1 ify ˆn+1 is sufficiently accurate. 2.1.2.3 Changing the Step Size The way in which we choose the next step length is as follows: suppose we are using a step length h then 2.1 Runge-Kutta Methods 19 p+1 yˆn+1 − yn+1 = h φ + h.o.t., (2.14) (where h.o.t. means higher order terms in h). Suppose we wish to change to a step αh.Wewant + (αh)p 1φ = tol, (2.15) so /( + ) tol 1 p 1 α = . (2.16) yˆn+1 − yn+1 In practice we allow a margin of error, and use for example /( + ) tol 1 p 1 α = 0.8 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us