Basics of IVPs
clear all
format short
set(0, 'defaultaxesfontsize', 12)
set(0, 'defaultlinelinewidth', 1.5)
set(0, 'defaultFunctionLinelinewidth', 1.5)
set(0, 'defaultscattermarkerfacecolor', 'flat')
gcf;
set(gcf, 'Position', [0 0 600 350], 'Theme', 'light')
addpath ../FNC_matlab6.1. Basics of IVP s ¶ A scalar first-order initial-value problem (IVP ) is
u ′ ( t ) = f ( t , u ( t ) ) , a ≤ t ≤ b , u ( a ) = u 0 . \begin{split}
u'(t) &= f(t,u(t)), \qquad a \le t \le b, \\
u(a) &=u_0.
\end{split} u ′ ( t ) u ( a ) = f ( t , u ( t )) , a ≤ t ≤ b , = u 0 . We call t t t the independent variable and u u u the dependent variable . If u ′ = f ( t , u ) = g ( t ) + u h ( t ) u'=f(t,u)=g(t)+u h(t) u ′ = f ( t , u ) = g ( t ) + u h ( t ) , the differential equation is linear ; otherwise, it is nonlinear .
A solution of an initial-value problem is a function u ( t ) u(t) u ( t ) that makes both u ′ ( t ) = f ( t , u ( t ) ) u'(t)=f\bigl(t,u(t)\bigr) u ′ ( t ) = f ( t , u ( t ) ) and u ( a ) = u 0 u(a)=u_0 u ( a ) = u 0 true equations.
When t t t is meant to be time, sometimes we write u ˙ \dot{u} u ˙ (read “u-dot”) instead of u ′ u' u ′ .
Suppose u ( t ) u(t) u ( t ) is the size of a population at time t t t . We idealize by allowing u u u to take any real (not just integer) value. If we assume a constant per capita birth rate (births per unit population per unit time), then
d u d t = k u , u ( 0 ) = u 0 \frac{d u}{d t} = k u, \qquad u(0)=u_0 d t d u = k u , u ( 0 ) = u 0 for some k > 0 k>0 k > 0 . The solution of this linear equation is u ( t ) = e k t u 0 u(t)=e^{kt}u_0 u ( t ) = e k t u 0 , which is exponential growth.
A more realistic model would cap the growth due to finite resources. Suppose the death rate is proportional to the size of the population, indicating competition. Then
d u d t = k u − r u 2 , u ( 0 ) = u 0 . \frac{d u}{d t} = ku - ru^2, \qquad u(0)=u_0. d t d u = k u − r u 2 , u ( 0 ) = u 0 . This is the logistic equation . Although crude, it is still useful in population models. The solution relevant for population models has the form
u ( t ) = k / r 1 + ( k r u 0 − 1 ) e − k t . u(t) = \frac{k/r}{ 1 + \left( \frac{k}{r u_0} - 1 \right) e^{-k t} }. u ( t ) = 1 + ( r u 0 k − 1 ) e − k t k / r . For k , r , u 0 > 0 k,r,u_0>0 k , r , u 0 > 0 , the solution smoothly varies from the initial population u 0 u_0 u 0 to a finite population, equal to k / r k/r k / r , that has been limited by competition.
Linear problems can be solved in terms of integrals. Defining the integrating factor ρ ( t ) = exp [ ∫ − h ( t ) d t ] \rho(t) = \exp\bigl[\int -h(t)\, dt \bigr] ρ ( t ) = exp [ ∫ − h ( t ) d t ] , the solution is derived from
ρ ( t ) u ( t ) = u 0 + ∫ a t ρ ( s ) g ( s ) d s . \rho(t) u(t) = u_0 + \int_a^t \rho(s) g(s) \, ds. ρ ( t ) u ( t ) = u 0 + ∫ a t ρ ( s ) g ( s ) d s . In many cases, however, the necessary integrals cannot be done in closed form. Some nonlinear ODE s, such as separable equations, may also be solvable with a short formula, perhaps with difficult integrations. Most often, though, there is no analytic formula available for the solution.
An ODE may have higher derivatives of the unknown solution present. For example, a second-order ordinary differential equation is often given in the form u ′ ′ ( t ) = f ( t , u , u ′ ) u''(t)=f\bigl(t,u,u'\bigr) u ′′ ( t ) = f ( t , u , u ′ ) . A second-order IVP requires two conditions at the initial time in order to specify a solution completely. As we will see in IVP systems , we are always able to reformulate higher-order IVP s in a first-order form, so we will deal with first-order problems exclusively.
6.1.1 Numerical solutions ¶ Let’s use a built-in method to define and solve the initial-value problem
u ′ = sin [ ( u + t ) 2 ] , t ∈ [ 0 , 4 ] , u ( 0 ) = − 1. u'=\sin[(u+t)^2], \quad t \in [0,4], \quad u(0)=-1. u ′ = sin [( u + t ) 2 ] , t ∈ [ 0 , 4 ] , u ( 0 ) = − 1. We must create a function that computes u ′ u' u ′ , an initial value for u u u , and a vector describing the time domain.
f = @(t, u) sin((t + u)^2);
u0 = -1;
tspan = [0, 4];
These ingredients are supplied to a solver function. A standard first choice of solver is called ode45.
[t, u] = ode45(f, [0, 4], u0);
fprintf("length(t) = %d, length(u) = %d\n", length(t), length(u))The solution is represented as a pair of vectors, t and u, where t contains the times at which the solution was computed and u contains the corresponding values of u ( t ) u(t) u ( t ) .
clf
plot(t, u, '-o')
xlabel("t")
ylabel("u(t)")
title(("Solution of an IVP"));You might want to know the solution at particular times other than the ones selected by the solver. That requires an interpolation. To do this automatically requires calling the solver with just one output argument, which is then supplied to deval to evaluate the solution at any time.
sol = ode45(f, [0, 4], u0);
u = @(t) deval(sol, t)'; % return a column vector
u(0:0.5:2)6.1.2 Existence and uniqueness ¶ There are simple IVP s that do not have solutions at all possible times.
The equation u ′ = ( u + t ) 2 u'=(u+t)^2 u ′ = ( u + t ) 2 gives us some trouble.
f = @(t, u) (t + u)^2;
u0 = 1;
tspan = [0, 1];
[t, u] = ode45(f, tspan, u0);Warning: Failure at t=7.853789e-01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.776357e-15) at time t. The warning message we received can mean that there is a bug in the formulation of the problem. But if everything has been done correctly, it suggests that the solution simply may not exist past the indicated time. This is a possibility in nonlinear ODE s.
clf
semilogy(t, u)
xlabel("t")
ylabel("u(t)")
title(("Finite-time blowup"));We can also produce an IVP that has more than one solution.
The following standard theorem gives us a condition that is easy to check and guarantees that a unique solution exists. But it is not the most general possible such condition, so there are problems with a unique solution that it cannot detect. We state the theorem without proof.
If the derivative ∂ f ∂ u \frac{\partial f}{\partial u} ∂ u ∂ f exists and ∣ ∂ f ∂ u ∣ \left|\frac{\partial f}{\partial u}\right| ∣ ∣ ∂ u ∂ f ∣ ∣ is bounded by a constant L L L for all a ≤ t ≤ b a\le t \le b a ≤ t ≤ b and all u u u , then the initial-value problem (6.1.1) has a unique solution for t ∈ [ a , b ] t\in [a,b] t ∈ [ a , b ] .
6.1.3 Conditioning of first-order IVP s ¶ In a numerical context we have to be concerned about the conditioning of the IVP . There are two key items in (6.1.1) that we might consider to be the data of the initial-value ODE problem: the function f ( t , u ) f(t,u) f ( t , u ) , and the initial value u 0 u_0 u 0 . It’s easier to discuss perturbations to numbers than to functions, so we will focus on the effect of u 0 u_0 u 0 on the solution, using the following theorem that we give without proof. Happily, its conditions are identical to those in Theorem 6.1.1 .
If the derivative ∂ f ∂ u \frac{\partial f}{\partial u} ∂ u ∂ f exists and ∣ ∂ f ∂ u ∣ \left|\frac{\partial f}{\partial u}\right| ∣ ∣ ∂ u ∂ f ∣ ∣ is bounded by a constant L L L for all a ≤ t ≤ b a\le t \le b a ≤ t ≤ b and all u u u , then the solution u ( t ; u 0 + δ ) u(t;u_0+\delta) u ( t ; u 0 + δ ) of u ′ = f ( t , u ) u'=f(t,u) u ′ = f ( t , u ) with initial condition u ( a ) = u 0 + δ u(a)=u_0+\delta u ( a ) = u 0 + δ satisfies
∥ u ( t ; u 0 + δ ) − u ( t ; u 0 ) ∥ ∞ ≤ ∣ δ ∣ e L ( b − a ) \left\|u(t;u_0+\delta)-u(t;u_0)\right\|_\infty \le |\delta| e^{L(b-a)} ∥ u ( t ; u 0 + δ ) − u ( t ; u 0 ) ∥ ∞ ≤ ∣ δ ∣ e L ( b − a ) for all sufficiently small ∣ δ ∣ |\delta| ∣ δ ∣ .
Numerical solutions of IVP s have errors, and those errors can be seen as perturbations to the solution. Theorem 6.1.2 gives an upper bound of e L ( b − a ) e^{L(b-a)} e L ( b − a ) on the infinity norm (i.e., pointwise) absolute condition number of the solution with respect to perturbations at an initial time. However, the upper bound may be a terrible overestimate of the actual sensitivity for a particular problem.
Consider the ODE s u ′ = u u'=u u ′ = u and u ′ = − u u'=-u u ′ = − u . In each case we compute ∂ f / ∂ u = ± 1 \partial f/\partial u = \pm 1 ∂ f / ∂ u = ± 1 , so the condition number bound from Theorem 6.1.2 is e b − a e^{b-a} e b − a in both problems. However, they behave quite differently. In the case of exponential growth, u ′ = u u'=u u ′ = u , the bound is the actual condition number.
clf
for u0 = [0.7, 1, 1.3] % initial values
fplot(@(t) exp(t) * u0, [0, 3]), hold on
end
xlabel('t')
ylabel('u(t)')
title(('Exponential divergence of solutions'));But with u ′ = − u u'=-u u ′ = − u , solutions actually get closer together with time.
clf
for u0 = [0.7, 1, 1.3] % initial values
fplot(@(t) exp(-t) * u0, [0, 3]), hold on
end
xlabel('t')
ylabel('u(t)')
title(('Exponential convergence of solutions'));In this case the actual condition number is one, because the initial difference between solutions is the largest over all time. Hence the exponentially growing bound e b − a e^{b-a} e b − a is a gross overestimate.
In general, solutions can diverge from, converge to, or oscillate around the original trajectory in response to perturbations. We won’t fully consider these behaviors and their implications for numerical methods again until a later chapter.
6.1.4 Exercises ¶ ✍ For each IVP , determine whether the problem satisfies the conditions of Theorem 6.1.2 . If so, determine the smallest possible value for L L L .
(a) f ( t , u ) = 3 u , 0 ≤ t ≤ 1 f(t,u) = 3 u,\; 0 \le t \le 1 f ( t , u ) = 3 u , 0 ≤ t ≤ 1
(b) f ( t , u ) = − t sin ( u ) , 0 ≤ t ≤ 5 f(t,u) = -t \sin(u),\; 0 \le t \le 5 f ( t , u ) = − t sin ( u ) , 0 ≤ t ≤ 5
(c) f ( t , u ) = − ( 1 + t 2 ) u 2 , 1 ≤ t ≤ 3 f(t,u) = -(1+t^2) u^2,\; 1 \le t \le 3 f ( t , u ) = − ( 1 + t 2 ) u 2 , 1 ≤ t ≤ 3
(d) f ( t , u ) = u , 0 ≤ t ≤ 1 f(t,u) = \sqrt{u},\; 0 \le t \le 1 f ( t , u ) = u , 0 ≤ t ≤ 1
✍ Use an integrating factor to find the solution of each problem in analytic form.
(a) u ′ = − t u , 0 ≤ t ≤ 5 , u ( 0 ) = 2 u' = -t u,\ 0 \le t \le 5,\ u(0) = 2 u ′ = − t u , 0 ≤ t ≤ 5 , u ( 0 ) = 2
(b) u ′ − 3 u = e − 2 t , 0 ≤ t ≤ 1 , u ( 0 ) = 5 u' - 3 u = e^{-2t},\ 0 \le t \le 1,\ u(0) = 5 u ′ − 3 u = e − 2 t , 0 ≤ t ≤ 1 , u ( 0 ) = 5
✍ Consider the IVP u ′ = u 2 u'=u^2 u ′ = u 2 , u ( 0 ) = α u(0)=\alpha u ( 0 ) = α .
(a) Does Theorem 6.1.1 apply to this problem?
(b) Show that u ( t ) = α 1 − α t u(t) = \dfrac{\alpha}{1-\alpha t} u ( t ) = 1 − α t α is a solution of the IVP .
(c) Does this solution necessarily exist for all t ∈ [ 0 , 1 ] t\in[0,1] t ∈ [ 0 , 1 ] ?
⌨ Using the method in Example 6.1.2 , compute solutions x ( t ) x(t) x ( t ) to the logistic equation with harvesting,
x ′ = k ( S − x ) ( x − M ) , 0 ≤ t ≤ 10 , x' = k (S-x)(x-M), \qquad 0\le t \le 10, x ′ = k ( S − x ) ( x − M ) , 0 ≤ t ≤ 10 , with k = S = 1 k=S=1 k = S = 1 and M = 0.25 M=0.25 M = 0.25 , for the initial conditions x ( 0 ) = 0.9 M x(0)=0.9M x ( 0 ) = 0.9 M , 1.1 M 1.1M 1.1 M , 1.5 M 1.5M 1.5 M , 0.9 S 0.9S 0.9 S , 1.1 S 1.1S 1.1 S , 3 S 3S 3 S . Show all the solutions together on one plot with 0 ≤ x ≤ 3 0\le x \le 3 0 ≤ x ≤ 3 . (Note: One of the solutions will throw a warning and fail to reach t = 10 t=10 t = 10 , but you can plot it anyway.)
⌨ (a) Using the method in Example 6.1.2 , solve the IVP u ′ = u cos ( u ) + cos ( 4 t ) u'=u\cos(u) + \cos(4t) u ′ = u cos ( u ) + cos ( 4 t ) , 0 ≤ t ≤ 10 0\le t \le 10 0 ≤ t ≤ 10 , u ( 0 ) = u 0 u(0) = u_0 u ( 0 ) = u 0 for u 0 = − 2 , − 1.5 , − 1 , … , 1.5 , 2 u_0 = -2,-1.5,-1,\ldots,1.5,2 u 0 = − 2 , − 1.5 , − 1 , … , 1.5 , 2 . Plot all the solutions on a single graph.
(b) All of the solutions in part (a) eventually settle into one of two periodic oscillations. To two digits of accuracy, find the value of u 0 u_0 u 0 in ( − 1 , 1 ) (-1,1) ( − 1 , 1 ) at which the selected long-term solution changes. (This will take repeated trials, narrowing down the range for u 0 u_0 u 0 each time.)
⌨ Experimental evidence (see Newton et al. (1981) ) shows that a 300-mg oral dose of caffeine, such as might be found in a large mug of drip-brewed coffee, creates a concentration of about 8 μ g \mu{\rm g} μ g /mL in blood plasma. This boost is followed by first-order kinetics with a half-life of about 6 hours (although this rate can vary a great deal from person to person). We can model the caffeine concentration due to one drink taken over half an hour via
x ′ ( t ) = − k x + C ( t ) , x ( 0 ) = 0 , x'(t) = -kx + C(t),\quad x(0)=0, x ′ ( t ) = − k x + C ( t ) , x ( 0 ) = 0 , where k = log ( 2 ) / 6 k=\log(2)/6 k = log ( 2 ) /6 and
C ( t ) = { 16 , 0 ≤ t ≤ 0.5 , 0 , t > 0.5. C(t) =
\begin{cases}
16, & 0\le t \le 0.5, \\
0, & t > 0.5.
\end{cases} C ( t ) = { 16 , 0 , 0 ≤ t ≤ 0.5 , t > 0.5. Solve the IVP and make a plot of the caffeine concentration for 12 hours. Then change k = log ( 2 ) / 8 k=\log(2)/8 k = log ( 2 ) /8 (half-life of 8 hours) and plot the solution again.
⌨ A reasonable model of the velocity v ( t ) v(t) v ( t ) of a skydiver is
d v d t = − g + k ( t ) m v 2 , v ( 0 ) = 0 , \frac{dv}{dt} = -g + \frac{k(t)}{m}v^2, \quad v(0)=0, d t d v = − g + m k ( t ) v 2 , v ( 0 ) = 0 , where g = 9.8 m/sec 2 g=9.8 \text{ m/sec}^2 g = 9.8 m/sec 2 is gravitational acceleration, m m m is the mass of the skydiver with parachute, and k k k quantifies the effect of air resistance. At the US Air Force Academy, a training jump starts at about 1200 m and has k = 0.4875 k=0.4875 k = 0.4875 for t < 13 t<13 t < 13 and k = 29.16 k=29.16 k = 29.16 for t ≥ 13 t\ge 13 t ≥ 13 . (This is an oversimplification; see Meade & Struthers (1999) .)
(a) Solve the IVP for v v v for an 80-kg cadet for t ∈ [ 0 , 200 ] t\in [0,200] t ∈ [ 0 , 200 ] , and plot the solution.
(b) The total distance fallen up to time t t t is ∫ 0 t v ( s ) d s \displaystyle\int_0^t v(s)\, ds ∫ 0 t v ( s ) d s . Use Function 5.7.1 to calculate and plot the altitude of the cadet as a function of time.
(c) In part (b), you should have found that the altitude becomes negative. Use Function 4.4.1 to determine accurately when the cadet reaches the ground.
Newton, R., Broughton, L. J., Lind, M. J., Morrison, P. J., Rogers, H. J., & Bradbrook, I. D. (1981). Plasma and Salivary Pharmacokinetics of Caffeine in Man. European Journal of Clinical Pharmacology , 21 (1), 45–52. 10.1007/BF00609587 Meade, D. B., & Struthers, A. A. (1999). Differential Equations in the New Millennium: The Parachute Problem. International Journal of Engineering Education , 15 (6), 417–424.