8.6 Exercises
285
Filename: osc_FE_general.py.
Exercise 8.24: Solving a Nonlinear ODE with Backward Euler
Let y be a scalar function of time t and consider the nonlinear ODE
y
+ y = ty
3 , t ∈ (0, 4), y(0) =
1
2
.
a) Assume you want to solve this ODE numerically by the Backward Euler method.
Derive the computational scheme and show that (contrary to the Forward Euler
scheme) you have to solve a nonlinear algebraic equation for each time step
when using this scheme.
b) Implement the scheme in a program that also solves the ODE by a Forward
Euler method. With Backward Euler, use Newton’s method to solve the algebraic
equation. As your initial guess, you have one good alternative, which one?
Let your program plot the two numerical solutions together with the exact
solution, which is known (e.g., from Wolfram Alpha) to be
y(t) =
√
2
√
7e 2t + 2t + 1
.
Filename: nonlinBE.py.
Exercise 8.25: Discretize an Initial Condition
Assume that the initial condition on u is nonzero in the finite difference method
from Sect. 8.4.12: u (0) = V 0 . Derive the special formula for u 1 in this case.
Filename: ic_with_V_0.pdf.
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0
International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing,
adaptation, distribution and reproduction in any medium or format, as long as you give appropriate
credit to the original author(s) and the source, provide a link to the Creative Commons licence and
indicate if changes were made.
The images or other third party material in this chapter are included in the chapter’s Creative
Commons licence, unless indicated otherwise in a credit line to the material. If material is not
included in the chapter’s Creative Commons licence and your intended use is not permitted by
statutory regulation or exceeds the permitted use, you will need to obtain permission directly from
the copyright holder.
285
Filename: osc_FE_general.py.
Exercise 8.24: Solving a Nonlinear ODE with Backward Euler
Let y be a scalar function of time t and consider the nonlinear ODE
y
+ y = ty
3 , t ∈ (0, 4), y(0) =
1
2
.
a) Assume you want to solve this ODE numerically by the Backward Euler method.
Derive the computational scheme and show that (contrary to the Forward Euler
scheme) you have to solve a nonlinear algebraic equation for each time step
when using this scheme.
b) Implement the scheme in a program that also solves the ODE by a Forward
Euler method. With Backward Euler, use Newton’s method to solve the algebraic
equation. As your initial guess, you have one good alternative, which one?
Let your program plot the two numerical solutions together with the exact
solution, which is known (e.g., from Wolfram Alpha) to be
y(t) =
√
2
√
7e 2t + 2t + 1
.
Filename: nonlinBE.py.
Exercise 8.25: Discretize an Initial Condition
Assume that the initial condition on u is nonzero in the finite difference method
from Sect. 8.4.12: u (0) = V 0 . Derive the special formula for u 1 in this case.
Filename: ic_with_V_0.pdf.
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0
International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing,
adaptation, distribution and reproduction in any medium or format, as long as you give appropriate
credit to the original author(s) and the source, provide a link to the Creative Commons licence and
indicate if changes were made.
The images or other third party material in this chapter are included in the chapter’s Creative
Commons licence, unless indicated otherwise in a credit line to the material. If material is not
included in the chapter’s Creative Commons licence and your intended use is not permitted by
statutory regulation or exceeds the permitted use, you will need to obtain permission directly from
the copyright holder.
