Vous êtes sur la page 1sur 11

Lecture Notes Numerical solutions of ODEs By. S.

M Alay-e-Abbas

Numerical Errors
There are two kind of errors associated with the numerical solutions of ODEs namely Truncation Errors Truncation error arise in the numerical solutions of ODEs due to the fact that the curve of y(x) between two points i.e. xn and xn+1 is not a straight line. This error arises due to Taylors expansion as

Comparing this with the Euler methods equation i.e.

We can write that the Taylors expansion as

In other words in each step of Euler method we incur a truncation error of the order h2 (i.e. O (h2)). Consider that we require to integrate over an interval of Unity (i.e. b-a = 1). This requires O(h-1) steps. If each step incurs error of O (h2) and the errors are simply cumulative than the net errors will be O(h). in other words the error associated with integrating the ode using Euler method is directly proportional to the step length. Thus if we want to keep the relative error below 10-6, then we would need to take about one million steps per unit interval in x. Since the truncation error in Euler method goes like h. therefore it is called a first order integration method. More generally a method is called nth order if its truncation error per step is hn+1.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Round off Error This error is associated with the computer. Computers do not perform the arithmetic operations to infinite accuracy. Computers are only capable of storing a floating point number to a fixed number of decimal places. For every type of computer there is a characteristic number n. which is defined as the smallest number which when taken away from the original number yields none zero result. Every floating point operation incurs a round off error which arises from the finite accuracy. Since Euler method requires O (h-1) steps therefore we must have O(h-1) floating point operations. And each step incurs O (n) round off errors than the net round off error will be Than the total error e associated with the approximation will be

Clearly the truncation error dominates at larger step length and the round off error dominates at smaller step length. The net error attains its minimum value eo = n1/2 when we set h = n1/2. There is no point in making the step length any smaller than n1/2. For an IBM PC the value of floating point error is n = 2.22 x 10-16. Therefore the practical length of error on such computers is 10-8. This is adequate for scientific computation. But for single precision the floating point numbers the value of n = 1.19 x 10-7, yielding the minimum value of error to be about 10-3. This value of approximation is not adequate for scientific calculations.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Numerical instabilities
Consider the following ODE

Where

subject to the boundary condition

The analytical solution of this ODE will be

the solution is monotonically decreasing (because of the exponential involved here and never repeats a value twice). We can solve this also by using the Eulers method xn = nh. The Euler method thus yields

Note that if

then

in other words, if the value

of h is made to large the function becomes monotonically increasing function of and the numerical solution diverges from the actual solution. This type of catastrophic solution of numerical method is called numerical instability.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Runge-Kutta Method
Euler method is not used in most scientific calculations because of the following two reasons. Firstly because of the large truncation error associated with it and secondly due to the numerical instability. Another method called Runge-Kutta method was developed by C.D.T Runge and M.W Kutta. The main source of error with the Euler method is that it evaluates the derivative at the beginning of the interval i.e. at xn. which makes it asymmetric with beginning and the end of the interval. We can construct a more better method by considering also the mid point between the intervals.

This summarization cancels out the first order error. Making the method second order. Therefore the above method is called second order Runge-Kutta method. Like wise three trial steps per interval yield fourth order R-K method. For an nth order R-K method the error associated with the approximation will be

where first term corresponds to the round off error and the second term corresponds to the truncation error. The minimum step length in this case will be h = e1/(1+n) for which we get

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

It is evident that eo decreases and h increases as n increases. We can take any value of n for approximation but the most suitable value of n which has proved to be most suitable and that is used most often in computational physics is n=4. This gives the fourth order R-K method as

An Example Calculation
Consider the following g set of ODEs

Subject to the initial conditions x(0) = 0 and v(0) = (k)1/2 at t=0. the analytical solution of this system will be

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Let us compare this result with the one obtained with the Euler method or the Rung-Kutta method. Let us integrate the above equations with k=1 and step size t=0 to t=10 and than taking the difference between the analytical solution and the numerical solution. Plotted against the step length h in a log-log graph shown above. Note: 1- All the calculations are performed with single precision i.e. using float rather than double. 2- It can be seen that error associated with the Euler method becomes greater than unity at large values of h. this means that the error associated with numerical solution greatly exceeds the analytical solution. Indicating numerical instability. 3- There are no signs of instabilities with the R-K method

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

4- At intermediate h the errors associated with Eulers method decreases like h-1. In this regime the dominant error is truncation error of first order. 5- In R-K method the truncation error scales like h-4. 6- Note also that as h is decreased the errors associated with both the methods start to jag (thrust up). 7- For Euler method the minimum error is 10-3 at h = 10-3 and for R-K method the minimum error is 10-5 at h = 10-1. 8- Clearly the R-K method is more accurate than the Euler method. Figure below shows that when double precision is used instead of single precision then the main features remain the same as before but the round off error has been reduced to nine orders of magnitude. Allowing the R-K method to attain the minimum error of 10-12. Figure also shows why scientist uses R-K method and Double precision.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Adaptive integration Method


Consider the following system

Subject to the boundary conditions Where

The above solutions variation scale length decreases rapidly as t increases. Let us compare the analytical result with that obtained with the R-K method. Let us take than finding the difference between the numerical solutions and plotting against t we get the following graph . And

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

Notes: 1- The result shows that the error starts off small but than increases rapidly with t and than becomes unacceptable we can reduce this error by reducing the step length, h. 2- The step length needs to be reduced at large t but there is no need to reduce step size at small values of t. This attribute can be handled by varying the step size with increasing values of t to make the truncation error constant. This type of scheme is called adaptive integration method. To convert the fixed step R-K method we need to find an approximation of the truncation error. Suppose that the current step length is h. we can estimate the truncation error by finding the difference between the solutions obtained by h/2 twice and by h once. Let eo be the desired truncation error per step. Observe from the

That the truncation error scales like h5. So our step length adjustment formula should also take the form

According to this formula the step length should be increased if the truncation error per step is too small and vice versa such that the relative error per step remains relatively constant i.e. eo. In a system of n equations the truncation error e must be an average error associated with each equation.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

10

Figure above shows the fixed step R-K method result and an adaptive method result. The errors are calculated by integrating the above system with and from and then taking the difference between adaptive and analytical solution. It can be seen that the adaptive method gives relatively better results that the simple routine. Figure below shows how this is achieved by changing the values of the step size as we go from the initial values to the final values.

Lecture Notes Numerical solutions of ODEs By. S.M Alay-e-Abbas

11

Advanced Methods
Runge kutta methods are not the last words in integrating the odes. These methods are called single step methods because they evolve from xn to xn+1 without needing to know the solution at xn-1 and xn-2. There are other methods like Adams Methods and predictor corrector methods that use this technique. Main advantages of R-K methods are that they are self starting and very stable. And main disadvantages are that they require more computer time and they do not yield good estimate of truncation error.

Vous aimerez peut-être aussi