390 likes | 563 Views
Numerical Analysis. Lecture 41. Examples of Differential Equations. Recall EULER METHOD. We considered the differential equation of first order with the initial condition y ( t 0 ) = y 0. We obtained the solution of the given differential equation in the form of a recurrence relation.
E N D
NumericalAnalysis Lecture 41
Recall • EULER METHOD
We considered the differential equation of first order with the initial condition y(t0) = y0.
We obtained the solution of the given differential equation in the form of a recurrence relation
In fact Euler’s method constructs wi ~ y(ti ) for each i = 0, 1,…, N-1 by deleting the remainder term. Thus the Euler’s Method is
Euler’s algorithm Let us try to approximate the solution of the given IVP at (N+1) equally spaced numbers in the interval [a ,b]
INPUT endpoints a, b; integer N, initial condition (alpha) OUTPUTapproximate w to y at the (N+1) values of t
Step 1 Set h=(b-a) / N t = a w = (alpha) OUTPUT(t , w) Step 2 For i = 0,1,…N do Step 3, 4.
Step 3 Set w = w + h f (t , w); (compute wi ). t = a + i h (compute ti ) Step 4 OUTPUT (t , w) Step 5 STOP
Example Use Euler’s method to approximate the solution of IVP y’= y - t2 + 1, 0 < t < 2, y ( 0 ) = 0.5 with N = 10.
Solution Here, h = 0.2, ti = 0.2i, w0= 0.5 and wi+1 = wi + h (wi - ti2 + 1) = wi+0.2[wi - 0.04i2 +1] =1.2 wi - 0.008i2 + 0.2 for i = 0,1,…,9. The exact solution is y ( t )= (t+1)2 -0.5 et
> alg051(); This is Euler's Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 > y-t^2+1
Input left and right endpoints separated by blank > 0 2 Input the initial condition > 0.5 Input a positive integer for the number of subintervals > 10 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 > 1
Output t w 0.000 0.5000000 0.200 0.8000000 0.400 1.1520000 0.600 1.5504000 0.800 1.9884800 1.000 2.4581760
> alg051(); This is Euler's Method. Input the function F (t,y) in terms of t and y For example: y-3*t^2+4 > y-3*t^2+4
Input left and right hand points separated by a blank >0 1 Input the initial condition > 0.5 Input a positive integer for the number of subintervals > 10 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 > 1
Output t w 0.000 0.5000000 0.100 0.9500000 0.200 1.4420000 0.300 1.9742000 0.400 2.5446200 0.500 3.1510820 0.600 3.7911902 0.700 4.4623092 0.800 5.1615401 0.900 5.8856942 1.000 6.6312636
Recall • Runge-Kutta (Order Four) METHOD
Example Solve the following differential equation with the initial condition y(0) = 1, using fourth- order Runge-Kutta method from t = 0 to t = 0.4 taking h = 0.1
Solution The fourth-order Runge-Kutta method is described as (1) where
In this problem, As a first step, we calculate
Now, we compute from Therefore y(0.1) = y1=1.1103 In the second step, we have to find y2 = y(0.2)
From Equation (1), we see that Similarly we calculate,
Using equation (1), we compute Finally, we calculate
Using them in equation (1), we get which is the required result.
RK4 algorithm Let us try to approximate the solution of the given IVP at (N+1) equally spaced numbers in the interval [a ,b]
INPUT endpoints a, b; integer N, initial condition (alpha) OUTPUTapproximate w to y at the (N+1) values of t
Step 1 Set h=(b-a) / N t = a w = (alpha) OUTPUT(t , w) Step 2 For i = 0,1,…N do Step 3 - 5.
Step 3 Set
Step 3 Set w = w + h f (t , w); (compute wi ). t = a + i h (compute ti ) Step 4 OUTPUT (t , w) Step 5 STOP
> alg052(); This is the Runge-Kutta Order Four Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 > y-t^2+1
Input left and right endpoints separated by blank > 0 2 Input the initial condition > 0.5 Input a positive integer for the number of subintervals > 10 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 > 1
Output t w 0.000 0.5000000 0.200 0.8292933 0.400 1.2140762 0.600 1.6489220 0.800 2.1272027 1.000 2.6408227 1.200 3.1798942 1.400 3.7323401 1.600 4.2834095 1.800 4.8150857 2.000 5.3053630
NumericalAnalysis Lecture 41