Ordinary Differential Equations Initial Value Problems
The question of whether computers can think is just like the question of whether submarines can swim
1
Edsger W. Dijkstra
Ordinary Differential Equations Initial Value Problems The question - - PowerPoint PPT Presentation
Ordinary Differential Equations Initial Value Problems The question of whether computers can think is just like the question of whether submarines can swim Edsger W. Dijkstra 1 Fall 2010 Topics to Be Discussed Topics to Be Discussed This
The question of whether computers can think is just like the question of whether submarines can swim
1
Edsger W. Dijkstra
2
'
'
3
y0’=f(x0,y0) unknown y(x) h di d the predicted y1 exact solution
4
x0 x0+∆
5
∆ = (b-a)/n x = a ! Initial values ! [a,b] y = y(a) DO i = 1, n y = y + ∆×f(x,y) ! x0 = a ! y0 = y(a) = y(x0) ! n: # of subdivisions
6
x = x + ∆ END
x y y’=f(x,y)
Init 2 0 2 0 2 5 2+0 25×(0+2) Init 2.0 2.0 2.5=2+0.25×(0+2) 1 0.25 2.5 2.75 3.1875=2.5+0.25×2.75 2 0 5 3 1875 3 6875 4 109375=3 1875+0 25×3 6875 2 0.5 3.1875 3.6875 4.109375 3.1875+0.25×3.6875 3 0.75 4.109375 4.859375 5.3245187=4.109375+0.25×4.859375
4 1
5 3245187
7
4 1
5.3245187
hi i h d l i
8
x0 x1 x2 x3 this is the expected solution
x y exact y |error| % of exact 1 1/6 0.1666667 0.1535182 0.01314841 8.56 2 1/3 0.3055556 0.2834687 0.02208686 7.79 3 1/2 0.4212963 0.3934693 0.02782699 7.07 4 2/3 0.5177469 0.4865829 0.03116405 6.40 5 5/6 0.5981224 0.5654018 0.03272063 5.79 6 1 0.6651020 0.6321206 0.03298146 5.22
9
y’(x+∆) (y’(x)+y’(x+∆))/2 y’=f(x y) (y (x) y (x ∆))/2 y =f(x,y) y(x)+∆×f(x,y)
10
x x+∆
P
P
11
∆ = (b-a)/n x = a ! initialization ! [a,b]: interval a y = y(a) DO i = 1, n ypred = y + ∆×f(x y) ! Euler’s ! [a,b]: te a ! x0 = a ! y0 = y(a) = y(x0) ! n : intervals yp = y + ∆×f(x,y) ! Euler s y = y + ∆×(f(x,y) + f(x+∆,ypred))/2 x = x + ∆ END DO ! n : intervals END DO
12
x y exact y |error| % of exact 1 1/6 0.15277778 0.15351826 0.00074048 0.48 2 1/3 0.28221452 0.28346872 0.00125420 0.44 3 1/2 0.39187619 0.39346933 0.00159314 0.40 4 2/3 0.48478401 0.48658288 0.00179887 0.37 5 5/6 0.56349754 0.56540179 0.00190425 0.34
13
6 1 0.63018543 0.63212055 0.00193512 0.31
14
* *
15
16
ypred = y + ∆×f(x,y) y y × ( ,y) DO k = 1, MAX ycorrect = y + ∆×(f(x,y) + f(x+∆,ypred))/2 ! Fixed-point IF (|(ycorrect-ypred)/ycorrect| < ε) EXIT IF (|(y
)/y | < ε) EXIT ypred = ycorrect END DO y ycorrect
17
y = ycorrect
ε = 0.0005 x y exact y |error| % of exact Iters 1 1/6 0.15384677 0.15351826 0.00032851 0.21 4 ε 0.0005 2 1/3 0.28401792 0.28346872 0.00054920 0.19 3 3 1/2 0.39416370 0.39346933 0.00069436 0.18 3 4 2/3 0.48736477 0.48658288 0.00078189 0.16 3 5 5/6 0.56622791 0.56540179 0.00082612 0.15 3
18
6 1 0.63295889 0.63212055 0.00083834 0.13 3
19
1 1 2 2 1
n n n i i i
=
1 i=
1
2 2 2,1 1 3 3 3 1 1 3 2 2
3 3 3,1 1 3,2 2
,1 1 ,2 2 , 1 1
n n n n n n n
− −
i,j i
1 2 2 2,1 1
( , ) ( , ( ) ) k f x y k f x p y a k = = + ∆ + ∆
3 3 3,1 1 3,2 2
( , ( ) ) k f x p y a k a k = + ∆ + + ∆
,1 1 ,2 2 , 1 1
( , ( ) )
n n n n n n n
k f x p y a k a k a k
− −
= + ∆ + + + + ∆
22
1 1
1 1 1
23
( , ) ( , ( )) ( ) ( ) 2
P
f x y f x y x y x y x + + ∆ + ∆ + ∆ = + ∆
P
P
k k k1
k1 k2 k1
24
1 1 2 2
a2,1=1 p2=1
k2
1 2 2 2,1
2
h2, k2 and higher terms
2 2,1
∆2 and higher terms
25
2 2,1
g
2
1 2
1 2 2 2 2 2 2 1
2 2 2 2,1
26
2
∆3 and higher terms
2
( ') "( ) '( , ) ( ) ( ) d y y x f x y dx f f d = = ∂ ∂
( , ) ( , ) ( ) ( ) f x y f x y dy x y dx f f ∂ ∂ = + ∂ ∂ ∂ ∂
27
( , ) ( , ) ( , ) f x y f x y f x y x y ∂ ∂ = + ∂ ∂
2
∆3 and higher terms
2
d g e e s
2 1
∆3 and higher terms
28
1 2 2 2 2 2 2 1
2 2 2 2,1
2 1
29
1 2
1 c c + =
1 2
1 c c = −
2 2 2 2,1
1/ 2 1/ 2 c p c a = =
2 2 2,1 2
1/(2 ) 1/(2 ) p c a c = =
30
2 1
2,1
1 2 2 2 1
31
2 2,1 2
2 1
2,1
1 2 2 2 1
32
2 2,1 2
2 1
2,1
1 2 2 2 1
33
2 2,1 2
∆ = (b-a)/n x = a DO i = 1, n ! Initialization ! [a,b] : input ! n : intervals DO i 1, n k1 = f(x,y) k2 = f(x+p2*∆, y+a21*k1*∆) y = y + ∆*(c1*k1 + c2*k2) c2 = 2.0/3.0 c1 = 1 – c2 y = y + ∆*(c1*k1 + c2*k2) x = x + ∆ END c1 1 c2 p2 = 1/(2*c2) a21 = 1/(2*c2)
34
for Ralston method general second-order Runge-Kutta method
0.8 0.5 0.5
x x x
− −
predictor-corrector
x Exact y Euler % Heun % P-C % Ralston % x Exact y Euler % Heun % P-C % Ralston % 2 2 2 2 2 1 6.19463 5.00000 19.3 6.70108 8.2 6.36053 2.7 6.44232 4.0 2 14.84392 11.40216 23.2 16.31978 9.9 15.30125 3.1 15.58216 5.0 3 33.67717 25.51321 24.2 37.19925 10.5 34.74091 3.2 35.45657 5.3
35
4 75.33897 56.84931 24.5 83.33777 10.6 77.72971 3.2 79.39618 5.4 6 iterations
1 2 3 3 ⎡ ⎤ ⎛ ⎞
f(x+(3/4)∆, y+(3/4)∆f(x,y))
1 2 3 3 ( ) ( ) ( , ) , ( , ) 3 3 4 4 y x y x f x y f x y f x y ⎡ ⎤ ⎛ ⎞ + ∆ = + ∆ + + ∆ + ∆ ⎜ ⎟ ⎢ ⎥ ⎝ ⎠ ⎣ ⎦
f(x,y) f(x,y)=k1/∆
∆ k2/∆=f(x+(3/4)∆, y+(3/4)∆f(x,y))
36
(3/4)∆
1
2 1
3 1 2
37
1 2 3
1
2 1
3 2
4 3
38
1 2 3 4
1
( , ) k f x y =
2 1
1 1 , 4 4 1 1 1 k f x y k ⎛ ⎞ = + ∆ + ∆ ⎜ ⎟ ⎝ ⎠ ⎛ ⎞
3 1 2
1 1 1 , 4 8 8 1 1 k f x y k k k f k k ⎛ ⎞ = + ∆ + ∆ + ∆ ⎜ ⎟ ⎝ ⎠ ⎛ ⎞ + ∆ ∆ + ∆ ⎜ ⎟
4 2 3 5 1 4
, 2 2 3 3 9 , 4 16 16 k f x y k k k f x y k k = + ∆ − ∆ + ∆ ⎜ ⎟ ⎝ ⎠ ⎛ ⎞ = + ∆ + ∆ + ∆ ⎜ ⎟ ⎝ ⎠
5 1 4 6 1 2 3 4 5
, 4 16 16 1 2 12 12 8 , 3 7 7 7 7 f y k f x y k k k k k ⎜ ⎟ ⎝ ⎠ ⎛ ⎞ = + ∆ − ∆ + ∆ + ∆ − ∆ + ∆ ⎜ ⎟ ⎝ ⎠
39
1 3 4 5
3 7 7 7 7 1 ( ) ( ) 7 32 12 32 90 y x y x k k k k ⎝ ⎠ + ∆ = + ∆ + + +
( )
6
7k +
0.8 0.5 0.5
x x x
− −
x Exact y Ralston % 3rd % 4th % 6th % y 2 2 2 2 2 1 6.19463 6.44232 4.0 6.17568 0.31 6.20104 0.10 6.19469 0.00 2 14.84392 15.58216 5.0 14.78616 0.39 14.86248 0.13 14.84410 0.00 3 33.67717 35.45657 5.3 33.53672 0.42 33.72135 0.13 33.67760 0.00 4 75 33897 79 39618 5 4 75 01767 0 43 75 43918 0 13 75 33994 0 00
40
4 75.33897 79.39618 5.4 75.01767 0.43 75.43918 0.13 75.33994 0.00
41