neub mat 201 lecture 12: initial value problems
TRANSCRIPT
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e1
Initial value problems
Methods described here are for solving differential equations of the form:
𝑑𝑦
𝑑𝑥= 𝑓(𝑥, 𝑦)
The methods in this lecture are all one-step methods and have the general format:
𝑦𝑖+1 = 𝑦𝑖 + 𝜙ℎ
where ϕ is called an increment function, and is used to extrapolate from an old value yi to a new
value yi+1.
This is in a general function of
𝑁𝑒𝑤 𝑣𝑎𝑙𝑢𝑒 = 𝑂𝑙𝑑 𝑣𝑎𝑙𝑢𝑒 + 𝑠𝑙𝑜𝑝𝑒 × 𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒
According to this equation, the slope estimate of φ is used to extrapolate from an old value yi to a
new value yi+1 over a distance h (Fig. 1). This formula can be applied step by step to compute out into
the future and, hence, trace out the trajectory of the solution.
Figure 1 Graphical depiction of a one-step method.
All one-step methods can be expressed in the general form, with the only difference being the
manner in which the slope is estimated. As in the falling parachutist problem, the simplest approach
is to use the differential equation to estimate the slope in the form of the first derivative at xi. In
other words, the slope at the beginning of the interval is taken as an approximation of the average
slope over the whole interval. This approach, called Euler’s method, is discussed in the next section.
This is followed by other one-step methods that employ alternative slope estimates that result in
more accurate predictions. All these techniques are generally called Runge-Kutta (RK) methods.
Euler’s Method
The first derivative provides a direct estimate of the slope at xi:
ii
x
yxfdx
dy
i
,
and the Euler method uses that estimate as the increment function:
𝜙 = 𝑓(𝑥𝑖 , 𝑦𝑖)
where f (xi, yi) is the differential equation evaluated at xi and yi. This estimate can be substituted to
get
𝑦𝑖+1 = 𝑦𝑖 + 𝑓 𝑥𝑖 , 𝑦𝑖 ℎ
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e2
This formula is referred to as Euler’s (or the Euler-Cauchy or the point-slope) method. A new value of
y is predicted using the slope (equal to the first derivative at the original value of x) to extrapolate
linearly over the step size h (Fig. 2).
Figure 2 Euler's method
Error analysis of Euler’s method
The numerical solution of ODEs involves two types of error:
– Truncation errors, caused by the nature of the techniques employed
– Roundoff errors, caused by the limited numbers of significant digits that can be retained
The total, or global truncation error can be further split into:
– local truncation error that results from an application method in question over a single
step, and
– propagated truncation error that results from the approximations produced during
previous steps.
The local truncation error for Euler’s method is O(h2) and proportional to the derivative of f(t,y)
while the global truncation error is O(h).
This means:
– The global error can be reduced by decreasing the step size, and
– Euler’s method will provide error-free predictions if the underlying function is linear.
Euler’s method is conditionally stable, depending on the size of h.
Higher order Taylor series method
One way to reduce the error of Euler’s method would be to include higher-order terms of the Taylor
series expansion in the solution. For example, including the second-order term
With a local truncation error of
Although the incorporation of higher-order terms is simple enough to implement for polynomials,
their inclusion is not so trivial when the ODE is more complicated. In particular, ODEs that are a
function of both the dependent and independent variable require chain-rule differentiation. For
example, the first derivative of f (x, y) is
The second derivative is
Higher-order derivatives become increasingly more complicated.
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e3
Heun’s Method
One method to improve Euler’s method is to determine derivatives at the beginning and predicted
ending of the interval and average them:
Figure 3Graphical depiction of Heun’s method. (a) Predictor and (b) corrector.
This process relies on making a prediction of the new value of y, then correcting it based on the
slope calculated at that new value.
From Eulers method
𝑦𝑖′ = 𝑓(𝑥𝑖 , 𝑦𝑖)
Is used to extrapolate linearly to 𝑦𝑖+1:
𝑦𝑖+10 = 𝑦𝑖 + 𝑓 𝑥𝑖 , 𝑦𝑖 ℎ
For the standard Euler method we would stop at this point. However, in Heun’s method the y0i +1
calculated in last equation is not the final answer, but an intermediate prediction. This is why we
have distinguished it with a superscript 0. This equation is called a predictor equation.It provides an
estimate of yi+1 that allows the calculation of an estimated slope atthe end of the interval:
𝑦𝑖+1′ = 𝑓(𝑥𝑖+1 ,𝑦𝑖+1
0 )
Thus, the two slopes can be combined to obtain an average slope for the interval:
This average slope is then used to extrapolate linearly from yi to yi+l using Euler’s method:
This is called corrector equation
This predictor-corrector approach can be iterated to convergence:
Error can be calculated using
where 𝑦𝑖+1𝑗−1
𝑎𝑛𝑑 𝑦𝑖+1𝑗
are the result from the prior and the present iteration of the corrector,
respectively.
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e4
Midpoint Method
Another improvement to Euler’s method is similar toHeun’s method, but predicts the slope at the
midpoint of an interval rather than at the end:
This method has a local truncation error of O(h3) and global error of O(h2)
Runge-Kutta (RK) Methods
Runge-Kutta (RK) methods achieve the accuracy of a Taylor series approach without requiring the
calculation of higher derivatives.
𝑦𝑖+1 = 𝑦𝑖 + 𝜙 𝑥𝑖 , 𝑦𝑖 , ℎ ℎ
For RK methods, the increment function ϕ can be generally written as:
nnkakaka 2211
where the a’s are constants and the k’s are
hkqhkqhkqyhpxfk
hkqhkqyhpxfk
hkqyhpxfk
yxfk
nnnnninin
ii
ii
ii
11,122,111,11
22212123
11112
1
,
,
,
,
where the p’s and q’s are constants.
Various types of Runge-Kutta methods can be devised by employing different numbers of terms in
the increment function as specified by n. Note that the first-order RK method with n = 1 is, in fact,
Euler’s method. Once n is chosen, values for the a’s, p’s,and q’s are evaluated
Classical Fourth-Order Runge-Kutta Method
The most popular RK methods are fourth-order, and the most commonly used form is:
hkkkkyy ii 43211 226
1
where:
hkyhxfk
hkyhxfk
hkyhxfk
yxfk
ii
ii
ii
ii
34
23
12
1
,2
1,
2
1
2
1,
2
1
,
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e5
Figure 4Graphical depiction of the slope estimates comprising the fourth-order RK method.
Systems of Equations
Many practical problems require the solution of a system of equations:
nn
n
n
n
yyyxfdt
dy
yyyxfdt
dy
yyyxfdt
dy
,,,,
,,,,
,,,,
21
212
2
211
1
The solution of such a system requires that n initial conditions be known at the starting value of x.
Solution Methods
Single-equation methods can be used to solve systems of ODE’s as well; for example, Euler’s method
can be used on systems of equations - the one-step method is applied for every equation at each
step before proceeding to the next step.
Fourth-order Runge-Kutta methods can also be used, but care must be taken in calculating the k’s.
1. Chapra examples 25.1, 25.5, 25.7 [To be done in class]
2. Chapra examples 25.2-25.3, 25.6 [ Home task]
3. Chapra examples 25.4 [For Lab]
4. Chapra exercise 25.1- 25.5
Self study
25.1.2 Algorithm for Euler’s Method
25.2.3 Computer Algorithms for Heun and Midpoint Methods
25.3.5 Computer Algorithms for Runge-Kutta Methods
25.3.1 Second-Order Runge-Kutta Methods
25.3.2Third-Order Runge-Kutta Methods
25.3.4 Higher-Order Runge-Kutta Methods
25.4 SYSTEMS OF EQUATIONS
Reading Materials 1. Numerical Methods for Engineers by Steven C. Chapra and Raymond P. Canale, McGraw Hills
Education, 6th Edition
a. Chapter 25
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e6
Examples to be done in class. Example 25.1:Euler’s Method
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e7
Example 25.5:Heun’s Method
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e8
Example 25.7
NEUB MAT 201 Lecture 12: Initial Value Problems
Prepared BY Shahadat Hussain Parvez
Pag
e9
The graph below shows
Figure 5 Comparison of percent relative error versus computational effort for first- through fifth-order RK methods