Sie sind auf Seite 1von 34

Chapter 8

Ordinary Differential Equations


§  Initial Value Problem (IVP)
1)  Euler’s Method
2)  Runge-Kutta Method (4th Order)

•  Boundary Value Problem (BVP)

Content
•  Consider function y = f ( x ) , where x is independent
variables, and ! dy d y $ are its ordinary
2

# , 2 ,... &
derivative " dx dx %

•  An equation that contains y = f ( x ) and its ordinary


derivatives is called ordinary differential equations
(ODE).
•  Examples : 2 dy + e x y = sin x
dx
d2y dy
2
+ 5 + 4y = tan x
dx dx

Initial Value Problem (IVP)


•  Consider an ODE with initial value; y' = y +1
y(0) = 5
•  The 1st-order differential equation for above ODE is
written as y' = f (x, y)
•  Using IVP, initial condition is given by y' = f (x, y) with (x0 )
show the initial point.
•  In Euler’s, the 1st order Taylor Series is written as:
yi+1 = yi + hyi ' = yi + hf (xi , yi )

Initial Value Problem (IVP): Euler’s


Example 8.1

Solve the following 1st-order IVP of x = 0(0.2)1 by Euler’s


method for the following ODE with initial value y(0) = 1
2x
2y'+ 3y = e
1 2 x 6 −32 x
Given the exact solution is y(x) = e + e
7 7

Initial Value Problem (IVP): Euler’s


Solutions :
Given ODE
2y'+ 3y = e 2 x
Write the above function in the form of y' = f (x, y)
2y' = e 2 x − 3y
e 2 x − 3y
y' =
2
e 2 x − 3y
y' = f (x, y) =
2
Initial condition y(0) = 1, means that y(x0 ) = y0 = y(0) = 1

Apply Euler’s formula to


h=0.2
approximate the value of yi by
x = 0(0.2)1 yi+1 = yi + hyi ' = yi + hf (xi , yi )
x0 x1 x2 x3 x4 x5
0 0.2 0.4 0.6 0.8 1.0
i xi yi Exact |Error|
Solution, yi yexact-yapproximate
0 0 1 1.000 0
1 0.2 0.800 0.848 0.048
2 0.4 0.709 0.788 0.079
3 0.6 0.719 0.823 0.104
4 0.8 0.835 0.966 0.131
5 1.0 1.080 1.247 0.167

Approximation Exact
yi+1 = yi + hyi ' = yi + hf (xi , yi ) 1 2 x 6 −32 x
y(x) = e + e
" e 2 x − 3y % 7 7
yi+1 = yi + 0.2 $ '
# 2 &
•  Q4 page 196.
The equation of motion of a car with mass m (kg) moving
with velocity v (m/s) and resistance c (N s/m) is given by
dv
m = −cv, v(0) = 10m / s
dt
with m=3000kg, c=90 N s/m. Estimate the velocity of the
car till time t=10s with Δt=1s. If the exact solution is
v(t)=10e-0.03t, find the absolute errors.

Exercise
•  Formula used in RK4;
1
yi+1 = y + ( k1 + 2k2 + 2k3 + k4 )
!i 6 ###"###$
valueof previous po int !
derivative at 4th order Taylor Series

where; k1 = hf (xi , yi )
! h k1 $
k2 = hf # xi + , yi + &
" 2 2%
! h k2 $
k3 = hf # xi + , yi + &
" 2 2%
k4 = hf ( xi + h, yi + k3 )

FOURTH-ORDER RUNGE-KUTTA METHOD (RK4)


Example 8.2

Solve the following 1st Order IVP at x = 0(0.2)0.4 by using


RK4 method. Given 2y'+ 3y = e 2 x and initial condition.
y(0) = 1

1 2 x 6 −32 x
Note that the exact solution is y(x) = e + e
7 7

FOURTH-ORDER RUNGE-KUTTA METHOD (RK4)


Solutions:
2x
Given ODE 2y'+ 3y = e
Write the above function in the form of y' = f (x, y)
2y' = e 2 x − 3y
e 2 x − 3y
y' =
2
e 2 x − 3y
y' = f (x, y) =
2
Initial condition y(0) = 1 , means that y(x0 ) = y0 = y(0) = 1
h=0.2

By sketch; x0 x1 x2
0 0.2 0.4

FOURTH-ORDER RUNGE-KUTTA METHOD (RK4)


1
•  Using RK4 formula; yi+1 = y
!i
+ ( k1 + 2k2 + 2k3 + k4 )
valueof previous po int
6 ###"###$
!
derivative at 4th order Taylor Series

•  Therefore, apply those classical formula RK4 into table


" e 2 x − 3y %
' = 0.1( e i − 3yi )
2x
k1 = hf (xi , yi ) = 0.2 $
# 2 &
" h k1 % " 2( xi +0.1) k1 %
k2 = hf $ xi + , yi + ' = 0.1$ e − 3(yi + )'
# 2 2& # 2 &
" h k2 % " 2( xi +0.1) k2 %
k3 = hf $ xi + , yi + ' = 0.1$ e − 3(yi + )'
# 2 2& # 2 &
k4 = hf ( xi + h, yi + k3 ) = 0.1( e 2( xi +0.2) − 3(yi + k3 ))
FOURTH-ORDER RUNGE-KUTTA METHOD (RK4)
i xi k1 k2 k3 k4 yi Exact Error
value
0 0 -0.200 -0.148 -0.156 -0.104 1.000 1.000 0
1 0.2 -0.105 -0.056 -0.064 -0.013 0.848 0.848 0
2 0.4 0.788 0.788 0

More
1 accurate!!
yi+1 = y + ( A + 2B + 2C + D )
!i 6 ###"###
valueof previous po int ! $

FOURTH-ORDER RUNGE-KUTTA METHOD (RK4)


•  Q4 page 196.
The equation of motion of a car with mass m (kg) moving
with velocity v (m/s) and resistance c (N s/m) is given by
dv
m = −cv, v(0) = 10m / s
dt
with m=3000kg, c=90 N s/m. Estimate the velocity of the
car till time t=10s with Δt=1s. If the exact solution is
v(t)=10e-0.03t, find the absolute errors.
Use RK4 method and compare your answer with Euler’s.

Tutorial
END OF PART 1
To be continued!
PART 2
Boundary Value Problem (BVP)
•  BVP approximate the
y(xi) values of a
system of linear yi+1 − yi−1
equations using y' ≈
FINITE
DIFFERENCE !#2h"# $
METHOD. 1st derivativeequation
•  This was done by
replacing the
derivatives for the yi+1 − 2yi + yi−1
linear differential y" ≈
equation with finite 2
!##"## h $
difference
2nd derivativeequation
approximation
formulas.

Boundary Value Problem


•  This method can be •  5 major STEPS
use for either BVP
with differentiation
or without STEP 1 •  Draw the diagram ordinate

differentiation by
substitute the “i” STEP 2 •  Find the boundary value/equation of
“y0” and “yn”
value with:
•  i=1, 2, 3…..n-1 STEP 3 •  Write the equation in finite difference
form.
(without
differentiation) •  From the system of linear equation,

•  i=0,1,2,3….n STEP 4 replace “i” using either with/without


differentiation.
(with
differentiation) STEP 5 •  Write in the matrix form and solve the
matrix using any suitable method.

Boundary Value Problem


Example 8.3 (without differentiation)

Solve the following using BVP without differentiation


method.
y"− xy'+ 3y = 11x 1 ≤ x ≤ 2,

Note that condition at the boundary y(1)=1.5 and y(2)=15,


and Δx=h=0.2

Boundary Value Problem


Solutions:
y0
h=0.2 y5
1.5
15
Step 1: x Diagram
ordinate
x0 x1 x2 x3 x4 x5
1.0 2.0

Step 2: y0=y(x0)=y(1)=1.5 Boundary


condition
yn=y(x5)=y(2)=15

Step 3: y"− xy'+ 3y = 11x


y"− xy'+ 3y −11x = 0 ……Equation 1

Boundary Value Problem


Continued
Step 3: Substitute the finite differentiation formula into
previous Equation 1.
" yi+1 − 2yi + yi−1 % " yi+1 − yi−1 %
$# '& − xi $# ' + 3yi −11xi = 0
h2 2h &
simplify
" y − 2yi + yi−1 % " yi+1 − yi−1 %
h 2 × $ i+1 2 ' − x i$ ' + 3yi −11xi = 0
# h & # 2h &
h
[ yi+1 − 2yi + yi−1 ] − xi [ yi+1 − yi−1 ] + 3yi h 2 −11xi h 2 = 0
2
substitute, h = 0.2
0.2
[ i+1 i i−1 ] i [ yi+1 − yi−1 ] + 3yi (0.2)2 −11xi (0.2)2 = 0
y − 2y + y − x
2
simplify to y = x
yi+1 (1− 0.1xi ) + yi−1 (1+ 0.1xi ) −1.88yi = 0.44xi

Boundary Value Problem


Step 4: Substitute the “i” value using 1=1,2,…., n-1
(without differentiation method)

i equation note
1 yi+1 (1− 0.1xi ) + yi−1 (1+ 0.1xi ) −1.88yi = 0.44xi x1=1.2
y1+1 (1− 0.1x1 ) + y1−1 (1+ 0.1x1 ) −1.88y1 = 0.44x1 y0=1.5
Substitute value x1, y0 into above equation y1
unknown
y2 (1− 0.1(1.2)) + (1.5)(1+ 0.1(1.2)) −1.88y1 = 0.44(1.2) y2
y2 (0.88) +1.68 −1.88y1 = 0.528
Simplify to system of linear equation
−1.88y1 + 0.88y2 = −1.152…system1
2 yi+1 (1− 0.1xi ) + yi−1 (1+ 0.1xi ) −1.88yi = 0.44xi x2=1.4
y2+1 (1− 0.1x2 ) + y2−1 (1+ 0.1x2 ) −1.88y2 = 0.44x2 y1
Substitute value x2 into above equation y2 unknown
y3 (1− 0.1(1.4)) + y1 (1+ 0.1(1.4)) −1.88y2 = 0.44(1.4) y3
y3 (0.86) + y1 (1.14) −1.88y1 = 0.616
Simplify to system of linear equation
1.14y1 −1.88y2 + 0.86y3 = 0.616…system2

Boundary Value Problem


i equation note
3 yi+1 (1− 0.1xi ) + yi−1 (1+ 0.1xi ) −1.88yi = 0.44xi x3=1.6
y3+1 (1− 0.1x3 ) + y3−1 (1+ 0.1x3 ) −1.88y3 = 0.44x3 y2
Substitute value x3 into above equation y3 unknown
y4 (1− 0.1(1.6)) + y2 (1+ 0.1(1.6)) −1.88y3 = 0.44(1.6) y4
0.84y4 +1.16y2 −1.88y3 = 0.704
Simplify to system of linear equation
1.16y2 −1.88y3 + 0.84y4 = 0.704…system3
4 yi+1 (1− 0.1xi ) + yi−1 (1+ 0.1xi ) −1.88yi = 0.44xi x4=1.8
(n-1) @ y4+1 (1− 0.1x4 ) + y4−1 (1+ 0.1x4 ) −1.88y4 = 0.44x4 y3
(5-1) Substitute value x2 into above equation y4 unknown
y5 (1− 0.1(1.8)) + y3 (1+ 0.1(1.8)) −1.88y4 = 0.44(1.8) y5=15
(15)(0.82) + y3 (1.18) −1.88y4 = 0.792
Simplify to system of linear equation
1.18y3 −1.88y4 = −11.508…system4

Step 5: write all system (1 to 4) in matrix form and use any


appropriate method to solve the system of linear equations.
Final solution using matrix
" −1.88 0.88 %" y % "
0 0 $ 1
' −1.152 %
$ '$ y ' $ '
$ 1.14 −1.88 0.86 0 '$ 0.616
=$ '
2

$ 0 '
1.16 −1.88 0.84 '$ y3 ' $ 0.704 '
$ 0 0 1.18 −1.88 '&$ y4 ' $# −11.508 '&
# # &
" y % "
$ 1 ' $ 2.844 %'
$ y2 ' $ 4.768 '
$ '=$
$ y3 ' $ 7.365 ''
$ y4 ' # 10.746 &
# &
Example 8.4 (with differentiation)

Solve the following using BVP with differentiation method.


3 4
y"− xy' = x − 3 1 ≤ x ≤ 2,
x
Note that condition at the boundary y’(1)=4 and
y’(2)-y(2)=1.5, and Δx=h=0.2

Boundary Value Problem


Solutions:
y0 h=0.2 y5

Step 1: x Diagram
ordinate
x0 x1 x2 x3 x4 x5
1.0 2.0

Boundary condition at start point


Step 2: at i=0, y0=y(x0)=y(1)
given y’(1)=4, use finite difference formula y’
yi+1 − yi−1 y −y
y'(1) ≈ = 4 ⇒ 0+1 0−1 = 4
2h 2(0.2)
at 1st derivative po int
y−1 = y1 −1.6…(i)

Boundary Value Problem


at i=n=5, y5=y(x5)=y(2)
y’(2)-y(2)=1.5
yi+1 − yi−1
y(2)=y’(2)-1.5 knowing, y' ≈
!#2h"# $
Substitute into 1st derivativeequation

y(2)=y’(2)-1.5

Boundary condition at end point


(y5+1 − y5−1 )
y5 = −1.5
2(0.2)
y −y
y5 = 6 4 −1.5
0.4
0.4y5 = y6 − y4 − 0.6
y6 = 0.4y5 + y4 + 0.6…(ii)
3 4
Step 3: given y"− xy' = x −
x3
substitute yi+1 − 2yi + yi−1
y" ≈ 2
!##"## h $
2nd derivativeequation

therefore, the new equation is


yi+1 − 2yi + yi−1 3 4
+ x y
i i = x i −
h2 xi3
simplify by "× h 2 " and substitute h = 0.2
2 4h 2
3 2
yi+1 − 2yi + yi−1 + xi yi h = x h − 3 i
xi
2 4(0.2)2
3 2
yi+1 − 2yi + yi−1 + xi yi (0.2) = x (0.2) − i
xi3
rearrange to
0.16
yi+1 + yi−1 − yi (2 − 0.04xi ) = 0.04xi3 −
xi3

Boundary Value Problem


Step 4: Substitute the “i” value using 1=1,2, 3…n (with
differentiation method)

i equation note
0.16
0 yi+1 + yi−1 − yi (2 − 0.04xi ) = 0.04xi3 − x0=1.0
xi3 y−1 = y1 −1.6
0.16 y0
y1 + y−1 − y0 (2 − 0.04x0 ) = 0.04x03 − unknown
x03 y1
Substitute value x0, y-1 into above equation
0.16
y1 + (y1 −1.6) − y0 (2 − 0.04(1)) = 0.04(1)3 −
(1)3
Simplify to system of linear equation
−1.96y0 + 2y1 = 1.48…(system1)

1 0.16
y2 + y0 − y1 (2 − 0.04x1 ) = 0.04x13 − x1=1.2
x13 y0
Substitute value x1 into above equation y1 unknown
0.16 y2
y2 + y0 − y1 (2 − 0.04(1.2)) = 0.04(1.2)3 −
(1.2)3
Simplify to system of linear equation
y0 −1.952y1 + y2 = −0.023…(system2)
i equation note
2 0.16 x2=1.4
y3 + y1 − y2 (2 − 0.04x2 ) = 0.04x23 −
x23 y1
Substitute value x2 into above equation y2 unknown
0.16 y3
y3 + y1 − y2 (2 − 0.04(1.4)) = 0.04(1.4)3 −
(1.4)3
Simplify to system of linear equation
y1 −1.944y2 + y3 = 0.051…(system3)

3 0.16 x3=1.6
y4 + y2 − y3 (2 − 0.04x3 ) = 0.04x33 −
x33 y2
Substitute value x3 into above equation y3 unknown
0.16 y4
y4 + y2 − y3 (2 − 0.04(1.6)) = 0.04(1.6)3 −
(1.6)3
Simplify to system of linear equation
y2 −1.936y3 + y4 = 0.125…(system4)
i equation note
4 0.16 x4=1.8
y5 + y3 − y4 (2 − 0.04x4 ) = 0.04x43 −
x43 y3
Substitute value x4 into above equation y4 unknown
0.16 y5
y5 + y3 − y4 (2 − 0.04(1.8)) = 0.04(1.8)3 −
(1.8)3
Simplify to system of linear equation
y3 −1.993y4 + y5 = 0.206…(system5)

5 0.16 x5=2.0
y6 + y4 − y5 (2 − 0.04x5 ) = 0.04x53 −
x53 y4
unknown
Substitute value x5 and y6 into above equation y5
0.16 y6 = 0.4y5 + y4 + 0.6
(0.4y5 + y4 + 0.6) + y4 − y5 (2 − 0.04(2.0)) = 0.04(2.0)3 −
(2.0)3
Simplify to system of linear equation
24y4 −1.520y5 = −0.300…(system6)

Step 5: write all system (1 to 6) in matrix form and use any appropriate
method to solve the system of linear equations.
Final solution using matrix
" y % " %
" −1.96 2 0 0 0 0 %$ 1 ' $ 1.480
$ '$ y ' '
−0.023
$ 1 −1.952 1 0 0 0 '$ 2 ' $ '
$ 0 1 −1.944 1 0 0 '$ y3 ' $ 0.051 '
$ 0 ' =$ 0.125 '
0 1 −1.936 1 0 $ y '
$ '$ 4 ' $ '
$ 0 0 0 1 −1.993 1 '$ y5 ' $ 0.206 '
$# 0 0 0 0 2 −1.520 '&$ y ' $# −0.300 '
&
# 6 &
" y % " %
$ 1 ' $ −0.970 '
$ y2 ' $ −0.211 '
$ ' $ 0.535 '
y
$ 3 '=$ '
$ y4 ' $ 1.302 '
$ ' $ 2.111 '
y
$ 5 ' $ '
$ y ' # 2.975 &
# 6 &
•  Tutorial Exercise (Q 9 & 10, page 197). Use suitable
method for each question.

Boundary Value Problem


END OF CHAPTER 8
Thank You

Das könnte Ihnen auch gefallen