CSE 330 : Numerical Methods Lecture 17: Solution of Ordinary Differential Equations (a) Euler’s Method (b) Runge-Kutta Method Dr. S. M. Lutful Kabir Visiting Research Professor, BRAC University & Professor (on leave) IICT, BUET 1 Prof. S. M. Lutful Kabir, BRAC University
Euler’s Method Φ Step size, h x y x 0,y 0 True value y 1, Predicted value Slope Figure 1 Graphical interpretation of the first step of Euler’s method Prof. S. M. Lutful Kabir, BRAC University2
Euler’s Method Φ Step size h True Value y i+1, Predicted value yiyi x y xixi x i+1 Figure 2. General graphical interpretation of Euler’s method Prof. S. M. Lutful Kabir, BRAC University3
How to write Ordinary Differential Equation Example is rewritten as In this case How does one write a first order differential equation in the form of Prof. S. M. Lutful Kabir, BRAC University 4
Example A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K. Assuming heat is lost only due to radiation, the differential equation for the temperature of the ball is given by Find the temperature at seconds using Euler’s method. Assume a step size of seconds. Prof. S. M. Lutful Kabir, BRAC University5
Solution Step 1: is the approximate temperature at Prof. S. M. Lutful Kabir, BRAC University6
Solution Cont For Step 2: is the approximate temperature at Prof. S. M. Lutful Kabir, BRAC University7
Solution Cont The exact solution of the ordinary differential equation is given by the solution of a non-linear equation as The solution to this nonlinear equation at t=480 seconds is Prof. S. M. Lutful Kabir, BRAC University8
Comparison of Exact and Numerical Solutions Figure 3. Comparing exact and Euler’s method Prof. S. M. Lutful Kabir, BRAC University9
Step, h (480) EtEt |є t |% − Effect of step size Table 1. Temperature at 480 seconds as a function of step size, h (exact) Prof. S. M. Lutful Kabir, BRAC University10
Comparison with exact results Figure 4. Comparison of Euler’s method with exact solution for different step sizes Prof. S. M. Lutful Kabir, BRAC University11
Effects of step size on Euler’s Method Figure 5. Effect of step size in Euler’s method. Prof. S. M. Lutful Kabir, BRAC University12
Errors in Euler’s Method It can be seen that Euler’s method has large errors. This can be illustrated using Taylor series. As you can see the first two terms of the Taylor series The true error in the approximation is given by are the Euler’s method. Prof. S. M. Lutful Kabir, BRAC University13
Runge Kutta 2 nd Order Method Runge Kutta thought to consider upto second derivative terms in Taylor’s series In that case the Eular’s Method will be extended to But finding the second derivative is sometimes difficult Hence they used the average of two approximate slopes as follows: where, 14Prof. S. M. Lutful Kabir, BRAC University
Runge Kutta Method (Heun’s Method) x y xixi x i+1 y i+1, predicted y i Figure 1 Runge-Kutta 2nd order method (Heun’s method) Prof. S. M. Lutful Kabir, BRAC University15
Example A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K. Assuming heat is lost only due to radiation, the differential equation for the temperature of the ball is given by Find the temperature at seconds using Heun’s method. Assume a step size of seconds. Prof. S. M. Lutful Kabir, BRAC University16
Solution Step 1: Prof. S. M. Lutful Kabir, BRAC University17
Solution Cont Step 2: Prof. S. M. Lutful Kabir, BRAC University18
Comparison with exact results Figure 2. Heun’s method results for different step sizes Prof. S. M. Lutful Kabir, BRAC University19
Effect of step size Table 1. Temperature at 480 seconds as a function of step size, h Step size, h (480) EtEt |є t |% − − − − (exact) Prof. S. M. Lutful Kabir, BRAC University20
21 Runge-Kutta 4 th Order Method where For Runge Kutta 4 th order method is given by Prof. S. M. Lutful Kabir, BRAC University
22 Example A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K. Assuming heat is lost only due to radiation, the differential equation for the temperature of the ball is given by Find the temperature at seconds using Runge-Kutta 4 th order method. seconds. Assume a step size of Prof. S. M. Lutful Kabir, BRAC University
23 Solution Step 1: Prof. S. M. Lutful Kabir, BRAC University
24 Solution Cont is the approximate temperature at Prof. S. M. Lutful Kabir, BRAC University
25 Comparison with exact results Figure 1. Comparison of Runge-Kutta 4th order method with exact solution Prof. S. M. Lutful Kabir, BRAC University
Step size, h (480) EtEt |є t |% − Effect of step size Table 1. Temperature at 480 seconds as a function of step size, h (exact) Prof. S. M. Lutful Kabir, BRAC University
THANKS Prof. S. M. Lutful Kabir, BRAC University27