05 Ex Numerical Methods
05 Ex Numerical Methods
4. Consider any autonomous IVP y 0 = f (y), y(0) = y0 . Can you show, that one step of Heuns
method will always give the correct first-order approximation to the solution y(h)? (We
would be very impressed!)
5. Consider the IVP
For a small ∆ > 0. The exact solution looks as follows (the circle marks x(0))
1
0.8
0.6
x
0.4
0.2
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
t
The dashed part is not relevant for us. For t > 0, the solution approaches monotonically
the value x = 1. Despite this ”‘boring”’ behaviour, the ODE is not easy for an explicit
solver.
a) Find the maximum step size (depending on ∆) that guarantees, x̂1 < 1
b) Find the equation for x̂1 for the implicit Euler method. (You don’t need to solve it!)
c) Show that the equation for x̂1 for the implicit Euler method has a solution in the interval
]x0 , 1[ for any stepsize h > 0
6. The value of a company grows with a rate proportional to the square root of its actual
value. Two years ago, it was 1 Mio CHF, now it is 1.44 Mio CHF. When will the value be
2 Mio CHF?
7. Approximate Euler’s number e, using numerical solutions of the IVP
ẋ(t) = x(t)
x(0) = 1
for t = 1 with step width h = 1 (1.e. one step only), with the following methods
a) Explicit Euler
b) Midpoint Rule
c) Heun’s method
d) 4th order Runge-Kutta
x0 = 0
x1 = x0 + hf (t0 , x0 ) = 0 + 0.5 · (cos(0 + 0) + sin(0 − 0)) = 0.5
x2 = x1 + hf (t1 , x1 ) = 0.5 + 0.5 · (cos(0.5 + 0.5) + sin(0.5 − 0.5)) ≈ 0.770
d) With ode45
x(1) ≈ 0.6540
b) Five steps of Eulers method h = 0.4, i.e. t0 = 0, t1 = 0.4, t2 = 0.8, t3 = 1.2, t4 = 1.6,
t5 = 2 and f (t, x) = t · x:
x0 = 0.1
x1 = x0 + hf (t0 , x0 ) = 0.1
x2 = x1 + hf (t1 , x1 ) = 0.116
x3 = x2 + hf (t2 , x2 ) = 0.15312
x4 = x3 + hf (t3 , x3 ) ≈ 0.226618
x5 = x4 + hf (t4 , x4 ) ≈ 0.37165
The implicit Euler method gives ŷ1 = 1 + hŷ1 which we can solve explicitely for
1
ŷ1 = = 1 + h + h2 + h3 + . . .
1−h
where we used the geometric series (or equivalently the taylor-expansion of the fraction
1/(1 − h)). The implicit Euler solution gives the correct first order term and contains
(wrong) higher order terms.
λt + C 2
x= , C ∈ R.
2
Inserting x(−2) = 106 and x(0) = 1.44 · 106 yields
C 2
= 1.44 · 106
2
−2λ+C 2
2 = 106
So C = 2400 and λ = 200. The solution of the IVP is therefore
x1 = x0 + h · f (t0 , x0 )
= 1+1·1
= 2
b) Midpoint rule:
h h
x1 = x0 + h · f t0 + , x0 + f (t0 , x0 )
2 2
= 1 + 1 · f (0.5, 1.5)
= 2.5
c) Heuns method:
m1 = f (t0 , x0 ) = 1;
m2 = f (t0 + h, x0 + hm1 )
= f (2, 1 + 1) = 2;
h
x1 = x0 + (m1 + m2 )
2
= 1 + 0.5(1 + 2)
= 2.5
d) Fourth order Runge-Kutta
m1 = f (t0 , x0 ) = 1;
h h
m2 = f (t0 + , x0 + m1 )
2 2
= f (0.5, 1 + 0.5) = 1.5;
h h
m3 = f (t0 + , x0 + m2 )
2 2
= f (0.5, 1 + 1.75) = 1.75;
m4 = f (t0 + h, x0 + hm3 )
= f (1, 3.75) = 2.75
h
x1 = x0 + (m1 + 2m2 + 2m3 + m4 );
6
1
= x0 + (1 + 2 · 1.5 + 2 · 1.75 + 2.75)
6
≈ 2.70833
x = Ke−t , K ∈ R.
Trial function for xs : xs = at + b with ẋs = a; inserting into the ODE: a = t − (at + b),
thus
0 = 1−a
,
a = −b
a = 1, b = −1 and thus xs = t − 1 the general solution is therefore
x = Ke−t + t − 1, K ∈ R.
With the initial condition x(0) = 1 we get K = 2 and the solution of the IVP is
x = 2e−t + t − 1.
Thus
x(2) = 2e2 − 1 ≈ 1.270670566473225
x0 = 1
h h
x1 = x0 + h · f t0 + , x0 + f (t0 , x0 )
2 2
= 1 + 1 · f (0.5, 1 + 0.5f (0, 1))
= 1
h h
x2 = x1 + h · f t1 + , x1 + f (t1 , x1 )
2 2
= 1 + 1 · f (1.5, 1 + 0.5f (1, 1))
= 1.5
c) Four steps with Heuns method and h = 0.5: t0 = 0 , t1 = 0.5, t2 = 1, t3 = 1.5, t4 = 2:
x0 = 1
0.5
x1 = 1 + (−1 + 0) = 0.75
2
0.5
x2 = 0.75 + (−0.25 + 0.375) = 0.78125
2
0.5
x3 = 0.78125 + (0.21875 + 0.609375) = 0.98828125
2
0.5
x4 = 0.98828125 + (0.51171875 + 0.755859375) = 1.30517578125
2
b)