CAPÍTULO VIII. DE LAS FACTURAS
51. CONTENIDO DE LAS FACTURAS
In this chapter we described Euler’s method for solving sets of ordinary differ- ential equations. The method is extremely simple from a conceptual and pro- gramming viewpoint. It is computationally inefficient in the sense that a great many arithmetic operations are necessary to produce accurate solutions. More efficient techniques should be used when the same set of equations is to be solved many times, as in optimization studies. One such technique, fourth- order Runge-Kutta, has proved very popular and can be generally recommended for all but very stiff sets of first-order ordinary differential equations. The set of equations to be solved is da dt¼ RAða, b, . . . , tÞ db dt¼ RBða, b, . . . , tÞ ð2:45Þ ... ...
A value oft is selected, and values for a, b, . . . are estimated by evaluating the functions RA,RB. . . . In Euler’s method, this evaluation is done at the initial point (a0, b0,. . . , t0) so that the estimate for a is just tRAða0, b0,. . . , t0Þ ¼ tðRAÞ0: In fourth-order Runge-Kutta, the evaluation is done at four points and the estimates fora, b, . . . are based on weighted averages of theRA,RB,. . . at these four points:
a ¼ tðRAÞ0þ 2ðRAÞ1þ 2ðRAÞ2þ ðRAÞ3 6
b ¼ tðRBÞ0þ 2ðRBÞ1þ 2ðRBÞ2þ ðRBÞ3
6 ð2:46Þ
... ...
where the variousR s are evaluated at the points a1¼ a0þ tðRAÞ0=2 a2¼ a0þ tðRAÞ1=2 a3¼ a0þ tðRAÞ2
ð2:47Þ with similar equations for b1, b2, b3, and so on. Time rarely appears explicitly in theR , but, should it appear,
t1¼ t0þ t=2 t2¼ t1 t3¼ t0þ t
Example 2.14: Use fourth-order Runge-Kutta integration to solve the following set of ODEs:
da dt¼ k1a 2 db dt¼ þk1a 2 k 2bc dc dt¼ k2bc
Use a0¼ c0¼ 30, b0¼ 0, k1¼ 0:01, k2¼ 0.02. Find a, b, and c for t ¼ 1. Solution: The coding is left to the reader, but if you really need a worked example of the Runge-Kutta integration, check out Example 6.4. The follow- ing are detailed results fort ¼ 1.0, which means that only one step was taken to reach the answer.
j ai bi ci (RA)j (RB)j (RC)j 0 30.000 0 30.000 18.000 9.000 0 1 21.000 4.500 30.000 8.820 1.710 2.700 2 25.590 0.855 28.650 13.097 6.059 0.490 3 16.903 6.059 29.510 5.714 0.719 3.576 Final : 18:742 3:970 28:341
Fort ¼ 0.5, the results for a, b, and c are
Final : 18:750 4:069 28:445
Results accurate to three places after the decimal are obtained witht ¼ 0.25: Final : 18:750 4:072 28:448
The fourth Runge-Kutta method converges O(t5). Thus, halving the step size decreases the error by a factor of 32. By comparison, Euler’s method con- verges O(t) so that halving the step size decreases the error by a factor of only 2. These remarks apply only in the limit as t ! 0, and either method can give anomalous behavior if t is large. If you can confirm that the data are converging according to the theoretical order of convergence, the conver- gence order can be used to extrapolate calculations to the limit ast ! 0.
Example 2.15: Develop an extrapolation technique suitable for the first- order convergence of Euler integration. Test it for the set of ODEs in Example 2.3.
Solution: Repeat the calculations in Example 2.3 but now reduce t by a factor of 2 for each successive calculation rather than by the factor of 4 used in the examples. Calculate the corresponding changes in a(tmax) and denote these changes by . Then should decrease by a factor of 2 for each calculation of a(tmax). (The reader interested in rigor will note that the error is halved and will do some algebra to prove that the are halved as well.) If was the change that just occurred, then we would expect the next change to be /2, the one after that to be /4, and so on. The total change yet to come is thus /2 þ /4 þ /8 þ . This is a geometric series that converges to . Using Euler’s method, the cumulative change yet to come is equal to the single change that just occurred. Thus, the extrapolated value for a(tmax) is the value just calculated plus the just calculated. The extrapolation scheme is illustrated for the ODEs in Example 2.3 in the following table:
Number
of steps a(tmax)
Extrapolated a(tmax) 2 16.3200 4 1.5392 17.8591 19.3938 8 2.8245 1.2854 4.1099 16 3.2436 0.4191 3.6626 32 3.4367 0.1931 3.6298 64 3.5304 0.0937 3.6241 128 3.5766 0.0462 3.6228 256 3.5995 0.0229 3.6225 512 3.6110 0.0114 3.6224 1024 3.6167 0.0057 3.6224 2048 3.6195 0.0029 3.6224 4096 3.6210 0.0014 3.6224 8192 3.6217 0.0007 3.6224 16384 3.6220 0.0004 3.6224 32768 3.6222 0.0002 3.6224 65536 3.6223 0.0001 3.6224 131072 3.6223 0.0000 3.6224
Extrapolation can reduce computational effort by a large factor, but compu- tation is cheap. The value of the computational reduction will be trivial for most problems. Convergence acceleration can be useful for complex problems or for the inside loops in optimization studies. For such cases, you should also consider more sophisticated integration schemes such as Runge-Kutta. It too can be extrapolated, although the extrapolation rule is different. The extrapolated factor for Runge-Kutta integration is based on the series
Thus, the total change yet to come is about 3% of the change that just occurred. As a practical matter, your calculations will probably achieve the required accu- racy by the time you confirm that successive changes in the integral really are decreasing by a factor of 32 each time. With modern computers and Runge- Kutta integration, extrapolation is seldom needed for the solution of ODEs. It may still be useful in the solution of the second-order, partial differential equa- tions treated in Chapters 8 and 9. Ordinary differential equation solvers are often used as part of the solution technique for PDEs. Extrapolation is used in some highly efficient ODE solvers. A variety of sophisticated integration tech- niques are available both as freeware and as commercial packages. Their use may be justified for design and optimization studies where the same set of equa- tions must be solved repetitively or when the equations are exceptionally stiff. The casual user need go no further than Runge-Kutta, possibly with adaptive step sizes where t is varied from step to step in the calculations based on error estimates. See Numerical Recipes by Press et al., as cited in the ‘‘Suggestions for Further Reading’’ section for this chapter, for a usable example of Runge-Kutta integration with adaptive step sizes.