Professional Documents
Culture Documents
I. Definition An equation that consists of derivatives is called a differential equation. Differential equations have applications in all areas of science and engineering. Mathematical formulation of most of the physical and engineering problems lead to differential equations. Differential equations are of two types 1) ordinary differential equation (ODE) 2) partial differential equations (PDE). An ordinary differential equation is that in which all the derivatives are with respect to a single independent variable. Examples of ordinary differential equation include 1) 2) So, it is important for engineers and scientists to know how to set up differential equations and solve them.
Note: In this part, we will see how to solve ODE of the form
dy = f (x, y ), y (0) = y 0 dx
II. Eulers Method
dy = f (x, y ), y (0) = y 0 dx
x = 0 , we are given the value of y = y 0 . Let us call x = 0 as x 0 . Now since we know the slope of y with respect to x , that is, f (x, y ) , then at x = x0 , the slope is f (x0 , y 0 ). Both x 0 and y 0 are known from the initial condition y (x0 ) = y 0 .
At
x0,y0
Step size, h x
y1 y0 x1 x0 = f (x 0 , y 0 ) =
Thus
y1 = y0 + f (x0 , y0 ) (x1 x0 )
If we consider
y1 = y0 + f (x0 , y0 ) h .
We are able now to use the value of is the predicted value at
x2 , y2 = y1 + f (x1, y1 ) h
y = yi at xi , then
x2 = x1 + h
Based on the above equations, if we now know the value of
yi +1 = yi + f (xi , yi ) h
This formula is known as the Eulers method and is illustrated graphically in Figure 2. In some books, it is also called the Euler-Cauchy method.
True Value
It can be seen that Eulers method has large errors. This can be illustrated using Taylor series.
2 3 dy y (xi +1 xi ) + 1 d 2 (xi +1 xi )2 + 1 d y (xi +1 xi )3 + ... 3 dx , yi 2! dx , y 2 1 3! dx , y 1 3 i i i yi +1 = yi + f ( xxii , yi ) + f ' ( xi , yi )(xi +x f ' ' ( xi , yi )(xxii+ 1 xi ) + 1 xi ) + ... 2! 3!
yi +1 = yi +
As you can see the first two terms of the Taylor series
Et =
The true error hence is approximately proportional to the square of the step size, that is, as the step size is halved, the true error gets approximately quartered. However from Table 1, we see that as the step size gets halved, the true error only gets approximately halved. This is because the true error being proportioned to the square of the step size is the local truncation error, that is, error from one point to the next. The global truncation error is however proportional only to the step size as the error keeps propagating from one point to another.
II. Runge-Kutta 2
nd
order
yi +1 = yi + f (xi , yi )h
This can be considered to be Runge-Kutta 1 order method. The true error in the approximation is given by
st
Et =
order method formula. This new formula would include one more term of
yi +1 = yi + f (xi , yi )h + dy = e 2 x 3 y, y (0) = 5 dx
1 f (xi , yi )h 2 2!
f (x, y ) = e2 x 3 y
Now since y is a function of x,
f (x, y ) =
f (x, y ) f (x, y ) dy + x y dx 2 x ( = (e 2 x 3 y ) + e 3 y ) (e 2 x 3 y ) x y 2 x 2 x = 2e + ( 3) e 3 y
= 5e2 x + 9 y
The 2
nd
yi +1 = yi + f (xi , yi )h + yi +1 = yi + e 2 xi
Kutta did was write the 2
nd
1 f (xi , yi )h 2 2! 1 3 yi h + 5e 2 xi + 9 yi h 2 2!
You could easily notice the difficulty of having to find order method as
yi +1 = yi + (a1k1 + a2 k 2 )h
where
f (x, y ).
yi +1 = yi + f (xi , yi )h +
gives three equations.
a2 p1 =
1 2
a1 + a2 = 1
1 2
a2q11 =
Since we have 3 equations and 4 unknowns, we can assume the value of one of the unknowns. The other three will then be determined from the three equations. Generally the value of a2 is chosen to evaluate the other three constants. The three values generally used for
a2 are
known as Heuns Method, Midpoint method and Ralstons method, respectively. II.1. Heuns method Here we choose a2
1 , giving 2
a1 =
1 2
p1 = 1 q11 = 1
resulting in
1 1 yi +1 = yi + k1 + k2 h 2 2
where
Average Slope =
yi
xi
xi+1
nd
= 1, giving
a1 = 0
p1 =
1 2 1 q11 = 2
resulting in
yi +1 = yi + k2h
where
k1 = f (xi , yi ) 1 1 k 2 = f xi + h, yi + k1h 2 2
II.3. Ralstons method Here we choose
a2 =
2 , giving 3
a1 =
1 3 3 p1 = 4 3 q11 = 4 1 2 yi +1 = yi + ( k1 + k 2 )h 3 3
resulting in
where
k1 = f (xi , yi ) 3 3 k 2 = f xi + h, yi + k1h 4 4
NOTE: How do these three methods compare with results obtained if we found
f (x, y ) directly?
We know that since we are including first three terms in the series, if the solution is a polynomial of order two or less (that is, quadratic, linear or constant), any of the three methods are exact. But for any other case the results will be different. Consider the following example
dy = e 2 x 3 y, y (0) = 5 dx
If we directly find the
yi +1 = yi + f (xi , yi )h +
where
y(0.6) = 1.0930
The exact solution 2 x
y(x ) = e
+ 4e3x
gives
t =
For the same problem, the results from the Euler and the three Runge-Kuttamethod are given below Comparison of Eulers and Runge-Kutta 2 y(0.6) Exact Value 0.96239 Euler 0.4955 48.514 Direct 2nd 1.0930 13.571 Heun 1.1012 14.423 Midpoint 1.0974 14.029 Ralston 1.0994 14.236
nd
order methods
th
h = xi +1 xi
The above equation is equated to the first five terms of Taylor series
yi +1 = yi + + 1d y 4! dx 4
4
dy dx
1d x , y (xi +1 xi ) +
i i
y
2
2! dx
1d 2 x , y (xi +1 xi ) +
i i
y
3 xi , y i
3! dx
(xi +1 xi )
xi , y i
(xi +1 xi )4
Knowing that
dy = f (x, y ) and xi +1 xi = h dx 1 1 1 yi +1 = yi + f (xi , yi )h + f ' (xi , yi )h 2 + f '' (xi , yi )h3 + f ''' (xi , yi )h 4 2! 3! 4!
Based on equating the above equations, one of the popular solutions used is
yi +1 = yi +
of the interval [xi,xi+1] using the Euler method to predict the y approximation there. 1 1 k3 = f xi + h, yi + k2 h This is an Improved Euler approximation for the slope at 2 2
the midpoint.
k1 = f (xi , yi ) This is the slope at xi. 1 1 k2 = f xi + h, yi + k1h This is an estimate of the slope at the midpoint 2 2
Errors There are two main sources of the total error in numerical approximations: 1. The global truncation error arises from the cumulative effect of two causes: At each step we use an approximate formula to determine yn+1 (leading to a local truncation error). The input data at each step are only approximately correct since in general (tn) yn. 2. Round-off error, also cumulative, arises from using only a finite number of digits.
It can be shown that the global truncation error for the Euler method is proportional to h, for the Improved Euler method is proportional to h2, and for the RungeKutta method is proportional to h4.