You are on page 1of 14

Forward Euler method Y = cos(t) with T = 10

y 0 = − sin(t) or y 0 = − sin(τ ), τ 0 = 1
Forward Euler method Y = cos(t) with T = 10

y 0 = − sin(t) or y 0 = − sin(τ ), τ 0 = 1

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839343] 2.718573e-04
1 5.000000e-04 20001 [-0.839207] 1.359670e-04
Forward Euler method Y = cos(t) with T = 10

y 0 = − sin(t) or y 0 = − sin(τ ), τ 0 = 1

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839343] 2.718573e-04
1 5.000000e-04 20001 [-0.839207] 1.359670e-04

y 0 = λ(u − cos(t)) − sin(t) using λ = −10:

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839116] 4.422607e-05
1 5.000000e-04 20001 [-0.839094] 2.211436e-05
Forward Euler method Y = cos(t) with T = 10

y 0 = − sin(t) or y 0 = − sin(τ ), τ 0 = 1

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839343] 2.718573e-04
1 5.000000e-04 20001 [-0.839207] 1.359670e-04

y 0 = λ(u − cos(t)) − sin(t) using λ = −10:

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839116] 4.422607e-05
1 5.000000e-04 20001 [-0.839094] 2.211436e-05

yn+1 = (1+hλ)yn −h λ cos(τn )+sin(τn ) , 1+0.001·(−10) = 0.99
Forward Euler method Y = cos(t) with T = 10

y 0 = λ(u − cos(t)) − sin(t) with λ = −900

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839072] 4.663858e-07
1 5.000000e-04 20001 [-0.839072] 2.332176e-07

yn+1 = (1+hλ)yn −h λ cos(τn )+sin(τn ) , 1+0.001·(−900) = 0.1
Forward Euler method Y = cos(t) with T = 10

y 0 = λ(u − cos(t)) − sin(t) with λ = −900

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [-0.839072] 4.663858e-07
1 5.000000e-04 20001 [-0.839072] 2.332176e-07

yn+1 = (1+hλ)yn −h λ cos(τn )+sin(τn ) , 1+0.001·(−900) = 0.1
y 0 = λ(u − cos(t)) − sin(t) with λ = −2100

i h N yN |y (T ) − yN |
0 1.000000e-03 10001 [nan] nan
1 5.000000e-04 20001 [-0.839072] 9.990911e-08

yn+1 = (1+hλ)yn −h λ cos(τn )+sin(τn ) , 1+0.001·(−2100) = −1.1
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π

3.2
3.0
3.1
2.5
3.0
2.0
2.9
1.5
2.8

2.7 1.0

2.6 0.5

2.5 0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 10 20 30 40 50 60

T =5 T = 60
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π
Time interval [0, 3] with h = 0.125, 0.05, 0.025, 0.005, 0.001:
3.5

3.0

2.5

2.0
refernece h=1e-05
h=0.125
1.5 h=0.05
h=0.025
h=0.005
h=0.001
1.0
0 1 2 3 4 5

good with h = 0.025, excellent with h = 0.001 (factor 100 larger


then reference
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π
Time interval [0, 5] with h = 0.125, 0.05, 0.025, 0.005, 0.001:
3.5

3.0

2.5

2.0
refernece h=1e-05
h=0.125
1.5 h=0.05
h=0.025
h=0.005
h=0.001
1.0
0 1 2 3 4 5

good with h = 0.025, excellent with h = 0.001 (factor 100 larger


then reference
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π
Now T = 60:
5
refernece h=1e-05
h=0.125
h=0.05
4 h=0.025
h=0.005
h=0.001
3

0
0 50 100 150 200 250 300

Why problems with the ’boring’ part?


Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π

Linearize (in y around y0 )

f (t, y ) = f (t, y0 )+∂y f (t, χ)(y −y0 ) = f (t, y0 )+20t cos(20tχ)(y −y0 )

factor in front of linear term 20t cos(20ty0 )y grows with t!


Stability h|λ| < 2 with λ = ∂y f (t, y ) = 20t cos(20ty ) indicates
1
h<
10t
1
adaptive time stepping: decrease h by factor of 2 if h > 10t .
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π
Linearize (in y around y0 )
f (t, y ) = f (t, y0 )+∂y f (t, χ)(y −y0 ) = f (t, y0 )+20t cos(20tχ)(y −y0 )
factor in front of linear term 20t cos(20ty0 )y grows with t!
Stability h|λ| < 2 with λ = ∂y f (t, y ) = 20t cos(20ty ) indicates
1
h<
10t
1
adaptive time stepping: decrease h by factor of 2 if h > 10t .
10 2
refernece h=1e-05
3.0 adaptive
h=0.001
2.5

2.0

1.5 10 3

h
1.0

0.5

0.0
10 4
Forward Euler method
y 0 = f (t, y ) := sin(20ty ) , y (0) = π

Here is what RK45 (the default version implemented in Python)


does - the results should be similar to MATLAB’s ode45:
3.2 10 1 10 1
adaptive adaptive
rk45 3.0 rk45
3.1
2.5
3.0
10 2 10 2
2.0
2.9

h
1.5
2.8
10 3
1.0 10 3
2.7
0.5
2.6
0.0
2.5 10 4 10 4
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 50 100 150 200 250 300
What does rk45 do?
PS: used res = solve ivp(rhs, [0,T], [Y0], rtol=1e-6, atol=1e-8)
default parameter choice doesn’t work quite that well...
3.2 10 1 10 1
adaptive adaptive
rk45 3.0 rk45
3.1
2.5
3.0
10 2 10 2
2.0
2.9

h
1.5
2.8
10 3
1.0 10 3
2.7
0.5
2.6
0.0
2.5 10 4 10 4
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 50 100 150 200 250 300

time steps used (up to T = 60)


RK45: 12859
our adaptive scheme: 27188
uniform: 60000
refernce: 600001

How many evaluations of f ?

You might also like