Numerical Solution of Ordinary Differential Equations€¦ · 3 0 2? 0 0 c 0 cc ccc Assume h = x...
Transcript of Numerical Solution of Ordinary Differential Equations€¦ · 3 0 2? 0 0 c 0 cc ccc Assume h = x...
Numerical Solution of 1st Order Ordinary Differential
Equations
Numerical Methods for Solving 1st order ODE
• Taylor Series Method
• Picard’s Method
• Runge Kutta Method
Taylor Series Method
Taylor series expansion of the function f(x) around a point of expansion x has the
following form:.......)(xy
2!
)x(x)(xy
1!
)x(x)y(xy(x) 0
2
00
00
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
Assume h = x – x0
Hint:
1- When the step h becomes small, the numerical solution becomes nearly the same as the
exact solution.
2- y = f(x).
3- computing approximate values of the solution f(x) at the points: x1 = x0 +h, x2 = x0 +2h,
x3 = x0 + 3h,…
It is a numerical methods for solving ordinary differential equations
(O.D.Es) with a given conditions.y' = f(x, y), y(x0) = y0.
h),...y(xyh),y(xyh),y(xy 231201
Example 1 Solve the boundary value problem y’ = - y at x = 0.2, 0.4 given that
y(0) = 1.
2.002.00 xxh
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
1,)y(x)(xyy(x)y 00
Solution: Taylor expansion given by:
1,)(xy)(xy(x)y(x)y 00
1,)(xy)(xy(x)y(x)y 00
Then, .......)1(3!
)2.0()1(
2!
)2.0()1(
1!
2.01)2.00()2.0(
32
yy
Consider the point of expansion zero
Evaluate the derivatives at the point of expansion zero
.......)81867.0(3!
)2.0()81867.0(
2!
)2.0()81867.0(
1!
2.081867.0)2.02.0()4.0(
32
yy
81867.0
67022.0
Example 2 Solve the boundary value problem y’ = - 2x - y at x = 0.1, given that
y(0) = -1. Compare the answer with exact solution.
1.001.00 xxh
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
1,)y(xx2)(xyy2(x)y 000 x
Solution: Taylor expansion given by:
,3)(xy)(xy(x)y(x)y 00
,3)(xy2)(xy(x)y2(x)y 00
Then, .......)3(
3!
)1.0()3(
2!
)1.0()1(
1!
1.01)1.00()1.0(
32
yy
Consider the point of expansion zero
Evaluate the derivatives at the point of expansion zero
91451.0
Example 3 Solve the boundary value problem y’ = x + y at x = 1.1, given that
y(1) = 0. Compare the answer with exact solution.
1.011.10 xxh
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
1,)y(xx)(xyy(x)y 000 x
Solution: Taylor expansion given by:
Consider the point of expansion zero
Evaluate the derivatives at the point of expansion zero
,2)(xy)(xy(x)y(x)y 00
,2)(xy1)(xy(x)y1(x)y 00
Then,
.......)2(3!
)1.0()2(
2!
)1.0()1(
1!
1.00)1.01()1.1(
32
yy 11033.0
Example 4 Solve the boundary value problem at x = 0.1, given that
y(0) = 1. Compute the answer with four decimal accuracy.
1.001.00 xxh
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
1,)y(xx)(xyy(x)y 2
0
2
00
22 x
Solution: Taylor expansion given by:
Then,
Consider the point of expansion zeroEvaluate the derivatives at the point of expansion zero
y’ = x2 + y2
,8(x)y2)('22)(xy(x)y2)('22(x)y 2
0
2 yxyyxy
,2)(xy)(22)(xy(x)y22(x)y 0000 xyxyx
.......)28(!4
)1.0()8(
3!
)1.0()2(
2!
)1.0()1(
1!
1.01)1.00()1.0(
432
yy
11145.1
,28)(x''y')(2)(x'y')('6)(x''''
(x)''y')(2(x)'y')('2)('')('4(x)'''y'
00000
xyxyy
xyxyxyxy
= 1 + 0.1 + 0.01 + 0.0013333 + 0.000116666
Example 5 Solve the boundary value problem at x = 1.1, given that
y(1) = 1. Compute the answer with three decimal accuracy.
1.011.10 xxh
.......)(xy3!
h)(xy
2!
h)(xy
1!
h)y(xh)y(x 0
3
0
2
000
1,)y(xx)(xyy(x)y 1/3
000
1/3 x
Solution: Taylor expansion given by:
Then,
Consider the point of expansion zeroEvaluate the derivatives at the point of expansion zero
y’ = xy1/3
,3
4'
3
1)(xy'
3
1(x)y 3
1
003
2
0003
1
3
2
yyyxyyxy
.......)9
8(
3!
)1.0()
3
4(
2!
)1.0()1(
1!
1.01)1.01()1.1(
32
yy
10681.0= 1 + 0.1 + 0.00666 + 0.000148
,9
8
3
1
9
4
3
1
9
2
'3
1''
3
1'
3
1'
9
2)(xy'
3
1''
3
1'
3
1'
9
2(x)''' 0
3
2
003
2
0003
2
0
2
03
5
0003
2
3
2
3
2
23
5
yyyyxyyyyxyyyxyyyyxyy
Picard's Method of Successive Approximation
Let us consider the initial-value problem:
y‘ = f(x, y), y(x0) = y0
hx
x
hx
x
x
x
dxyxfyxy
dxyxfdydxyxfdyyxfdx
dy
yxfxy
0
0
0
0
0
),()(
),(),(),(
),()('
0
hx
x
kk dxxyxfyhxy0
0
)](,[)( )1(
00
)(
By, the fundamental theorem of calculus, since f(x, y)
is a continuous function of x due to continuity of f and y in
some domain. Thus y (x) satisfies initial value problem .
x
xdxyxf
0
),( 0
x
xdxxyxf
0
))(,( 1
x
xn dxxyxf
0
))(,(
Picard's Method of Successive Approximation
y1(x) = y0 +
y2(x) = y0 +
.................................
.................................
yn+1(x) = y0 +
Example 6 Find the Picard approximations y1, y2, y3 to the solution of
the initial value problem y‘ = y, y(0) = 2. Use y3 to estimate the value of
y (0.8) and compare it with the exact solution.
y1(x) = y0 + x
xdxyxf
0
),( 0
Solution: By, Picard's Method of Successive Approximation
Let y0 = 2, the value of y1 is
y1= 2 + x
dx0
2
y2(x) = y0 + x
xdxyxf
0
),( 1
x22
y2 = 2+ x
0(2 + 2x)dx = 2 + 2x + x2
y3(x) = y0 + x
xdxyxf
0
),( 2
y3 = 2 + x
dxxx0
2 )22(3
223
2 xxx
At x= 0.8
y3= 2 + 2(0.8) + (0.8)2 +3
1(0.8)3 = 4.41
The solution of the initial-value problem, found by
separation of variables, is y = 2ex. At x = 0.8
y(0.8) = 2e0.8 = 4.45
Example 7 Find the Picard approximations y1, y2, y3 to the solution of
the initial value problem y‘ = x + y, y(0) = 1. Use y3 to estimate the value
of y (0.2) and compare it with the exact solution.
y1(x) = y0 + x
xdxyxf
0
),( 0
Solution: By, Picard's Method of Successive Approximation
Let y0 = 1, the value of y1 is
y1= 1 + x
dxx0
)1(
y2(x) = y0 + x
xdxyxf
0
),( 1
xx
2
12
y2 = 1 + x
0(1 + 2x + )dx= 1+ x + x2
2
2x
6
3x
y3(x) = y0 + x
xdxyxf
0
),( 2
y3 = 1 + x
dxx
xx0
32 )
621(
2431
432 xx
xx
At x= 0.2
= 1.2427
The solution of the linear differential equation is,
y = - (x + 1) + 2ex.
y(0.2) = -1.2 + 2e0.2 = 1.243
24
2.0
3
2.02.02.01)2.0(
432 y
Runge-Kutta 4th Order Method
)(
)(
)(
)(
where,
)22(
34
221
21
3
121
21
2
1
432161
1
kh,yxhfk
kh,yxhfk
kh,yxhfk
,yxhfk
kkkkyy
nn
nn
nn
nn
nn
Copyright © Jones and Bartlett;滄海書局
Ch6_16
Example 18 Use the RK4 method with h = 0.5 to obtain y(0.5) for the solution of y’ = 2xy, y(0) = 1. Compare the answer with exact solution.Solution:
02)5.0(),( 00001 yxyxhfk
Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 0.5, x1 = 0.5
)(
)(
)(
)(
where
)22(
34
221
21
3
121
21
2
1
432161
1
kh,yxhfk
kh,yxhfk
kh,yxhfk
,yxhfk
kkkkyy
nn
nn
nn
nn
nn
By RK4 Method,
25.0))))(5.0((2)5.0(
))0(),5.0((
021
0
21
021
02
yx
yxhfk
28125.0)125.1)(25.0(2)5.0(
))25.0(),5.0((21
021
03
yxhfk
640625.0)28125.1)(5.0(2)5.0(
))28125.0(,5.0( 004
yxhfk
Copyright © Jones and Bartlett;滄海書局
Ch6_17
Therefore,
28379.1
)64025.0)28125.0(2)25.0(20(6
11
)22(6
1432101
kkkkyy
The exact solution of the problem is, y = ex^2, y(0.5) = 1.284
Copyright © Jones and Bartlett;滄海書局
Ch6_18
Example 19 Use the RK-4 method with h = 1 to obtain y(1) for the solution of y’ = 2xy, y(0) = 1. Compare the answer with exact solution.Solution:
02)1(),( 00001 yxyxhfk
Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 1, x1 = 1
)(
)(
)(
)(
where
)22(
34
221
21
3
121
21
2
1
432161
1
kh,yxhfk
kh,yxhfk
kh,yxhfk
,yxhfk
kkkkyy
nn
nn
nn
nn
nn
By RK-4 Method,
1)1)(5.0(2)1(
))0(),1((21
021
02
yxhfk
5.1)5.1)(5.0(2)1(
))1(),1((21
021
03
yxhfk
5)5.2)(1(2)1(
))5.1(,1( 004
yxhfk
Copyright © Jones and Bartlett;滄海書局
Ch6_19
Therefore,
6667.2
)5)5.1(2)1(20(6
11
)22(6
1432101
kkkkyy
The exact solution of the problem is, y = ex^2, y(1) = 2.7183
Copyright © Jones and Bartlett;滄海書局
Ch6_20
Example 20 A certain chemical reaction takes place such that the time-rate of change of the amount of the unconverted substance q is equal to -2q. If the initial mass is 50 grams, use the RK method to estimate the amount of unconverted substance at t = 0.8 sec.
Solution:
80)2)(8.0(),( 0001 yyxhfk
Here f (x, y) = -2y, x0 = 0, y0 = 50, h = 0.8, x1 = 0.8
)(
)(
)(
)(
where
)22(
34
221
21
3
121
21
2
1
432161
1
kh,yxhfk
kh,yxhfk
kh,yxhfk
,yxhfk
kkkkyy
nn
nn
nn
nn
nn
By RK-4 Method,
16))10(2)(8.0(
))80(),8.0((21
021
02
yxhfk
2.67)42(2)(8.0(
))16(),8.0((21
021
03
yxhfk
52.27))2.17(2)(8.0(
))2.67(,8.0( 004
yxhfk
The initial-value problem isdt
dq= -2q, q(0) = 50
Copyright © Jones and Bartlett;滄海書局
Ch6_21
Therefore,
52.13
)52.27)2.67(2)16(280(6
150
)22(6
1432101
kkkkyy
Therefore our estimate of the mass of unconverted substance at t = 0.8 is 13.52gm.
Copyright © Jones and Bartlett;滄海書局
Ch6_22
Example 21 Use the RK-4 method to obtain y(0.2) for the solution of y’ = , y(0) = 1.
Solution:
2.0)1)(2.0(),( 001 yxhfk
Here f (x, y) = , x0 = 0, y0 = 1
Take h = 0.2, x1 = 0.2
)(
)(
)(
)(
where
)22(
34
221
21
3
121
21
2
1
432161
1
kh,yxhfk
kh,yxhfk
kh,yxhfk
,yxhfk
kkkkyy
nn
nn
nn
nn
nn
By RK-4 Method,
1967.0)9836.0)(2.0(
))2.0(),2.0((21
021
02
yxhfk
2 2
2 2
y x
y x
2 2
2 2
y x
y x
1967.0)9836.0)(2.0()1891.1,1.0(2.0
))1967.0(),1((21
021
03
f
yxhfk
1891.0)9457.0)(2.0(
))1967.0(,2.0( 004
yxhfk
Copyright © Jones and Bartlett;滄海書局
Ch6_23
Therefore,
196.1
)1891.0)1967.0(2)1967.0(22.0(6
11
)22(6
1432101
kkkkyy