using Plots, LaTeXStrings, OrdinaryDiffEq13 P1: Hints
Problem Class 1: Initial Value Problems
Make sure we are all happy with the examples/exercises from lectures 1-4.
Exercise 13.1 Consider the problem: u : [0,T] \to \mathbb R
\begin{align} u(0) &= u_0 \nonumber\\ u'(t) &= f\big( t, u(t) \big). \tag{IVP} \end{align}
For each of the following functions f and time intervals [0,T] does (\text{IVP}) has a unique solution?
- (i) f(t, u) = t^2 \sin u and T = 1,
- (ii) f(t, u) = \sqrt[3]{u} and T = 5,
- (iii) f(t, u) = \mu u, T = 2026.
Answer.
(i) f is smooth and Lipschitz in its second component so we can apply the thereom from lectures to conclude there exists a unique solution for all time. Can you prove this function is Lipschitz in its second component?
(ii) f(t,u) is not Lipschitz in any interval containing 0 so we cannot apply the existence and uniqueness theory. In fact, there is infinitely many solutions. Show that, when u_0 = 0, the function u(t) = \pm \left( \tfrac23(t + c) \right)^{\frac32} is a solution (for any constant c). Extra: what if u_0 \not= 0?
(iii) We have the solution u(t) = u_0 e^{\mu t}. It is unique because f is continuous and Lipschitz in the second component.
Exercise 13.2 Explain why the IVP
\begin{align} u(0) &= 1 \nonumber\\ u'(t) &= u(t) + e^{-t} \end{align}
has a unique solution for all time. Compute the solution using the integrating factor.
Answer.
This is u' = f with f(t,u) = u + e^{-t}, a continuous function that is Lipschitz continuous in the second component. We can therefore apply our result from lectures to conclude the existence of a unique solution.
The integrating factor (in this case) is I(t) = e^{-t} so that
\begin{align} (Iu)'(t) &= I(t) \left( u'(t) - u(t) \right) \nonumber\\ % &= I(t) e^{-t} = e^{-2t}. \end{align}
Therefore, we have e^{-t} u(t) = u_0 + \int_0^t e^{-2s} \mathrm{d}s which gives the solution u(t) = \frac32 e^t - \frac12 e^{-t}.
We plot our solution and the numerical solution below (the two lines are on top of each other):
f(u,p,t) = u + exp(-t)
u0, tspan = 1., (0., 10.)
ivp = ODEProblem(f, u0, tspan)
sol = solve(ivp, Tsit5());
plot(sol,
title=L"u'=f(t,u)", legend=false,
xlabel=L"t", ylabel=L"u(t)")
plot!( t-> 3/2*exp(t)-exp(-2t)/2 )Exercise 13.3 Here, we plot solutions to
\begin{align} u(0) &= u_0 \nonumber\\ u'(t) &= \cos u(t) \end{align}
for different choices of initial values u_0.
f(u,p,t) = cos( u )
u0, tspan = 0., (0., 10.)
ivp = ODEProblem(f, u0, tspan)
sol = solve(ivp, Tsit5());
P = plot(sol,
title=L"u'=f(t,u)", legend=false, label="u0 = $u0",
xlabel=L"t", ylabel=L"u(t)")
for u0 = vcat(0:.1:2π, [π/2,π,3π/2,2π])
ivp = ODEProblem(f, u0, tspan)
sol = solve(ivp, Tsit5());
plot!(sol,
label="u0 = $u0",
xlabel=L"t", ylabel=L"u(t)")
end
display(P)What are the possible values \alpha for which u(t) \to \alpha as t\to\infty. Do all solutions have limits for large t?
Now add the term \sin t and consider
\begin{align} u(0) &= u_0 \nonumber\\ u'(t) &= \cos u(t) + \sin t. \end{align}
What do you expect to happen to the solutions? Change the code above to find out - was your hypothesis correct?
Answer.
If u(t) \to \alpha as t\to\infty, then the limiting solution is constant. That is, u'(t) = \cos u(t) = 0 and so \alpha \in \frac\pi2 + \pi\mathbb Z.
Now, even when \cos u(t) = 0, there is the forcing term \sin t which forces the solution to oscillate. See the lecture notes for a picture!
Exercise 13.4 Show that the following IVP is well-posed
\begin{align} u(0) &= 0 \nonumber\\ u'(t) &= t + u(t). \end{align}
Compute the first few terms of Euler’s method. Show that Euler’s method generates the sequence
\begin{align} u_j = (1 + h)^j - ( 1 + jh ). \end{align}
Check that the exact solution is given by u(t) = e^t - t- 1. Hence, prove an error bound for |u(t_j) - u_j| and compare with the error bound obtained from the Theorem from lectures.
Answer.
(i) Notice that f(t,u) := t + u is continous and Lipschitz in the second argument with constant L=1. Therefore, applying the result from lectures, we conclude that the initial value problem is well-posed.
(ii) We have u_1 = u_0 + h f(0, u_0) = 0 which is also (1+h)^1 - (1 + 1h). By assuming u_j = (1 + h)^j - ( 1 + jh ), we have
\begin{align} u_{j+1} &= u_j + h f(t_j, u_j) \nonumber\\ % &= \left[ (1 + h)^j - ( 1 + jh ) \right] + h\left[ t_j + (1 + h)^j - ( 1 + jh ) \right] \nonumber\\ % &= (1+h)(1 + h)^{j} - (1 + (j+1)h ). \end{align}
Here, we have used the fact that t_j = jh. Therefore, we can conclude by induction that u_j = (1 + h)^j - ( 1 + jh ) for all j.
(iii) We have u'(t) = e^t - 1 = t + \left( e^t - t- 1\right) = t + u(t) and u(0)= e^0 - 1 = 0.
(iv) The error is
\begin{align} \left| u_j - u(t_j) \right| &= \left| \big[ (1 + h)^j - ( 1 + jh ) \big] - (e^{jh} - jh - 1) \right| \nonumber\\ % &= \left| (1 + h)^j - e^{jh} \right| \nonumber\\ % &= \left| 1 + h - e^{h} \right| \sum_{i=0}^{j-1} (1+h)^{i} e^{(j-1-i) h} \nonumber\\ % &\leq \left( \frac{h^2}{2} e^h \right) j e^{(j-1)h } % \leq \frac{h}{2} t_j e^{t_j} \end{align}
Here, we have used the facts a^j - b^j = (a-b) \sum_{i=0}^{j-1} a^i b^{j-1-i}, 0 \leq 1+h \leq e^h, and e^h = 1 + h + \frac{h^2}{2}e^\xi for some \xi \in [0,h].
(v) Let’s compare this error estimate to the general one from lectures:
\begin{align} \left| u_j - u(t_j) \right| \leq \frac{hM}{2L} \left( e^{Lt_j} -1 \right) % = \frac{h}{2} e^{t_j} ( e^{t_j} -1 ) \end{align}
where L = 1 is the Lipschitz constant of f and M := \|u''\|_{L^\infty([0,t_j])} = e^{t_j}. For large t_j, we have \frac{h}{2} t_j e^{t_j} \ll \frac{h}{2} e^{t_j} ( e^{t_j} -1 ).
Exercise 13.5 Write down the method that corresponds to the Butcher tableau:
\begin{array} {c|cccc} 0\\ c & a \\ \hline & 0 & b \end{array}Exercise 13.6 Consider the IVP
\begin{align} u(0) &= 1 \nonumber\\ u'(t) &= u(t). \end{align}
Compute the terms in the following method
\begin{align} u_{j+1} &= u_j + \frac{h}{2} \left[ f(t_j, u_j) + f\big( t_{j+1}, u_j + h f(t_j, u_j) \big) \right] \end{align}
explicitly. What is the order of accuracy of this method?