%% 2. First-order scalar linear ODEs

%%
% <latex> 
% \setcounter{page}{10}
% </latex>

%%
% <latex>
% Problem (1.1) of the last chapter 
% could be regarded as the prototype of all ODE\kern .5pt s.  Slightly generalized,
% it takes the form
% $$ y' - a y = 0, \quad y(0) = y_0^{}, $$
% where $a$ and $y_0^{}$ are constants.  This problem
% has the solution
% $$ y(t) = y_0^{}e^{at}, $$
% which is as good an argument as any for why the number
% $e = 2.71828\dots$ is important.
% Let us make it a theorem (the proof is in the paragraphs
% following).
% </latex>

%%
% <latex> 
% \smallskip
% {\em
% {\bf Theorem 2.1.  Solution of first-order linear 
% autonomous scalar homogeneous IVP
% (\textsf{\textbf{FLASHI}}).}
% The problem
% $$ y'-a y = 0, \quad y(0) = y_0^{}, \eqno (2.1) $$
% where $a$ and $y_0^{}$ are constants, has the unique solution
% $$ y(t) = y_0^{} e^{at}. \eqno (2.2) $$
% }
% </latex>

%%
% <latex>
% \vskip -.5em
% Here are images for eleven values of $a$ from $-10$ to $10$, showing
% exponential growth for $a > 0$, exponential decay
% for $a <0$, and a constant solution for $a=0$.
% </latex>
ODEformats, L = chebop(0,1); L.lbc = 1;
for a = -10:2:10
  L.op = @(t,y) diff(y) - a*y; y = L\0; plot(y,CO,ivp), hold on
end
ylim([0 3]), hold off
title(['Fig.~2.1.~~Exponential growth or decay (2.2) ' ...
    ' depending on $a$'],FS,11)
text(.33,0.67,'$a=-2$',IN,LT,FS,10)
text(.66,1.17,'$a=0$',IN,LT,FS,10)
text(.43,2.20,'$a=2$',IN,LT,FS,10)
text(.23,2.30,'$a=4$',IN,LT,FS,10)
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% We can derive (2.2) by writing (2.1) as
% $$ {dy\over dt} = ay, $$
% or equivalently if $y \ne 0$
% $$ {dy\over y} = a\kern .5pt dt. $$
% (If $y(t)=0$ for some $t$ then $y(t)=0$ for all $t$, a case
% readily handled separately.)
% Note that the last step has separated the $y$ and $t$ terms
% onto the two sides of the equation: we say that (2.1) is {\bf separable,}
% and this technique is called {\bf separation of variables}.
% We now integrate both sides of the equation to get
% $$ \log |y| = a\kern .3pt t + c $$
% for some constant $c$,
% or after exponentiating both sides,
% $$ y(t) = C\kern -.2pt e^{a\kern .2pt t} $$
% with $C=e^c$ if $y>0$ and $C=-e^c$ if
% $y<0$ (a similar adjustment works if $y$ is
% complex).  Taking $C=y_0^{}$ gives (2.2).
% Moreoever, the solution is unique, since any solution $y(t)$
% must be of the form $C\kern -.2pt e^{a\kern .2pt t}$ by the reasoning just given,
% and only $C=y_0^{}$ will match the initial condition.
% </latex>

%%
% <latex>
% If $a>0$, then $y(t)$ increases exponentially
% with $t$, whereas if $a<0$ it decreases
% exponentially.  This simple
% distinction between exponential growth and decay of solutions
% to (2.1) is the starting point of the theory of stability
% of dynamical systems, a recurring theme in the second
% half of this book.\footnote{If $a$ is
% a complex number $\alpha + i\beta$,
% which makes perfectly good sense mathematically and changes
% none of the formulas, then since $e^{at} = e^{\alpha t}(\cos \beta\kern .3pt  t +
% i\sin\beta\kern .3pt  t),$ we have exponential increase for $\alpha >0$ and
% exponential decrease for $\alpha <0$.  In both cases the
% solution oscillates as well as growing or decaying.} 
% </latex>

%%
% Equation (2.1) is autonomous (coefficients independent of $t$)
% and homogeneous (zero right-hand side).
% Nothing much changes if we make the problem
% nonautonomous: we still obtain a
% solution via the method of separation of variables.
% What this means is that instead of a constant
% coefficient $a$, we allow a variable coefficient function $a(t)$.
% $$ y'-a(t) y=0, \quad y(0) = y_0^{}. \eqno (2.3) $$
% We separate variables as before to get 
% $$ {dy\over y} = a(t)\kern .5pt dt, $$
% which implies
% $$ \log y(t) =  \int_0^t a(s) ds + c, $$
% or equivalently
% $$ y(t) = C\exp\Bigl(\kern 1pt \int_0^t a(s) ds\Bigr) \eqno (2.4) $$
% for constants $c$ and $C = e^c$.  Since the integral takes
% the value $0$ for $t=0$, the right constant is $C=y_0^{}$.

%%
% <latex>
% In the derivation just made we have tacitly assumed $a$
% is continuous.  The integrals in (2.4) and the equation above
% it make sense more generally, however, for example if 
% $a$ is just {\em piecewise continuous.}  We use this term in its
% standard sense to refer to a function that is continuous apart
% from at most a finite set of jump discontinuities.
% With this in mind, the following
% theorem and Theorem~2.3 are stated for piecewise continuous functions,
% on the understanding that a solution is defined to be a continuous function
% that is differentiable and satisfies the ODE everywhere 
% except at the points of discontinuity.
% </latex>

%%
% <latex> 
% \smallskip
% {\em
% {\bf Theorem 2.2.  Solution of first-order linear scalar homogeneous IVP
% (\textsf{\textbf{FLaSHI}}).}
% The problem
% $$ y'-a(t) y = 0,
% \quad y(0) = y_0^{}, \eqno (2.5) $$
% where $y_0^{}$ is a constant and\/ $a(t)$ is a continuous or
% piecewise continuous function, has the unique solution
% $$ y(t) = y_0^{} \exp\Bigl(\kern 1pt\int_0^t a(s) ds\Bigr). \eqno (2.6) $$
% }
% </latex>

%%
% <latex>
% \vskip -.5em
% As an example, consider
% $$ y'=\sin(t^2) y, \quad t\in [\kern .3pt 0,8\kern .3pt ], \quad y(0) = 1. \eqno (2.7) $$
% A numerical solution gives an elegant oscillatory curve.
% </latex>
L = chebop(0,8); L.lbc = 1; L.op = @(t,y) diff(y) - sin(t^2)*y;
y = L\0; plot(y,CO,ivp), ylim([0.5 3])
title('Fig.~2.2.~~Smooth homogeneous ODE (2.7)',FS,11)
%%
% <latex> \vskip 1.02em </latex>
%%
% For an example with a coefficient that is only piecewise continuous,
% suppose we replace $\sin(t^2)$ by $\hbox{sign}(\sin(t^2))$,
% $$ y'=\hbox{sign}(\sin(t^2)) y,
% \quad t\in [\kern .3pt 0,8\kern .3pt ], \quad y(0) = 1. \eqno (2.8) $$
% This corresponds to a ``bang-bang'' situation in which
% the system is pushed one way and then the other, always
% with amplitude 1.
% Here is the solution.
L.op = @(t,y) diff(y) - sign(sin(t^2))*y; y = L\0; plot(y,CO,ivp)
title('Fig.~2.3.~~Nonsmooth homogeneous ODE (2.8)',FS,11)
ylim([0 7])
%%
% <latex> \vskip 1.02em </latex>
%%
% <latex>
% \noindent
% It is striking how this curve resembles the earlier one in form,
% though the vertical scale has changed 
% considerably.  Actually, this second example is mathematically
% simpler than the first, since it consists of nothing but an
% alternation of segments of exponential growth $C\kern -.2pt e^{\kern .3pt t}$ and
% exponential decay $C\kern -.2pt e^{-t}$.
% </latex>

%%
% <latex>
% Our problem is still homogeneous.  We are about to
% take the next step and introduce a nonzero right-hand side.
% Before doing this, however, let us examine the significance
% of homogeneity from an abstract point of view.
% Suppose we consider the ODE (2.5) {\em without\/} a boundary condition,
% $$ y'-a(t) y = 0, \quad t\in [\kern .3pt 0,d\kern .5pt]. \eqno (2.9) $$
% By the reasoning above, the solutions of this
% equation consist precisely of all functions of the form
% $C\kern -.5pt \exp(\int_0^t a(s) ds)$ for
% any constant $C$.  In other words, the set of solutions of (2.9)
% is a {\em vector space of dimension $1$} spanned by the
% basis function $\exp(\int_0^t a(s) ds)$.\footnote{We are using the idea of a vector
% space in its standard abstract sense.  A vector in this space
% is a function $y(t)$.}
% This conclusion applies to any first-order linear, scalar, homogeneous
% ODE.\ \ The boundary
% condition of an IVP selects one function out of the vector space.
% Later we shall see that a second-order linear, scalar, homogeneous
% ODE has a vector space of
% solutions of dimension $2$, third-order gives dimension 3, and so on.
% </latex>

%%
% <latex>
% Now let us modify (2.9) to make the ODE inhomogeneous,
% $$ y'-a(t) y = g(t), \quad t\in [\kern .3pt 0,d\kern .5pt] \eqno (2.10) $$
% for some function $g(t)$.
% Suppose that somehow or other, we find a function $y_{\rm p}^{}(t)$
% that satisfies (2.10).
% The subscript \kern .7pt p \kern.7pt stands for ``particular:''
% a solution to a linear inhomogeneous
% ODE is called a {\bf particular solution.}
% Now let $y_{\rm h}^{}$, with h standing for
% ``homogeneous,'' be any nonzero solution
% to the homogeneous ODE (2.9), such as $\exp(\int_0^t a(s) ds)$ from Theorem 2.2.
% Then for any constant $C$, the function
% $$ y_{\rm p}^{} + C y_{\rm h}^{} \eqno (2.11) $$
% is another solution to (2.10).  This is
% called the {\bf general solution} to (2.10).
% In the language of vector spaces, we
% can say that the set of solutions to the inhomogeneous ODE (2.10) is
% an {\em affine space}, which means, a vector space shifted
% by the addition of a constant vector (namely $y_{\rm p}$).
% </latex>

%%
% <latex>
% We have just presented the general framework for solving a first-order
% linear scalar inhomogeneous IVP:
% find a particular solution $y_{\rm p}$, then apply Theorem~2.2 to
% find a nonzero solution $y_{\rm h}^{}$ to the homogeneous problem.
% The solutions to the inhomogeneous problem are then all the
% functions of the form $y_{\rm p} + Cy_{\rm h}^{}$
% for any constant $C$, and we pick $C$ to match the initial condition.
% Beginning in Chapter~4 we shall extend the same idea
% to higher order ODE\kern .5pt s and systems of linear ODE\kern .5pt s.
% </latex>

%%
% <latex>
% How do we find a particular solution $y_{\rm p}$?
% There is a mechanical procedure that in principle
% achieves this, multiplication by a function known as an
% {\bf integrating factor}.  (We shall see two pages along that in
% practice, this approach may be more cumbersome
% than necessary; the easier alternative is called the
% method of undetermined coefficients.)   Define
% $$ h(t) = \int_0^t a(s) ds . $$
% Then the product rule for differentiation gives
% $$ [ e^{-h(t)} y(t) ]' = e^{-h(t)} [ y'(t) - y(t) h'(t)] , $$
% and since $h'(t) = a(t)$, (2.10) reduces this to
% $$ [ e^{-h(t)} y(t) ]' = e^{-h(t)} g(t). $$
% The function $e^{-h(t)}$ is the integrating factor.
% We can integrate both sides to get
% $$ e^{-h(t)}y(t) - y(0) = \int_0^t e^{-h(s)} g(s) ds, $$
% that is,
% $$ y(t) = e^{h(t)} y(0) + e^{h(t)} \kern -2pt \int_0^t e^{-h(s)} g(s) ds. $$
% </latex>
%%

%%
% <latex>
% Let us formulate this conclusion as a theorem.
% The derivation above can be regarded as a proof, at least apart
% from the statement of uniqueness.
% Alternatively, one could substitute (2.13) into (2.12)
% and verify that it is a solution.
% </latex>

%%
% <latex>
% \smallskip
% {\em
% {\bf Theorem 2.3.  Solution of first-order linear scalar inhomogeneous
% IVP (\textsf{\textbf{FLaSh\kern .5pt I}}).}
% The problem
% $$ y'-a(t) y = g(t), \quad y(0) = y_0^{}, \eqno (2.12) $$
% where $y_0^{}$ is a constant and
% $a(t)$ and $g(t)$ are continuous or
% piecewise continuous functions, has the unique solution
% $$ y(t) = y_0^{} \exp\Bigl(\kern 1pt\int_0^t a(s)ds\Bigr) 
% + \int_0^t g(s) \exp\Bigl(\kern 1pt\int_s^t a(r)dr\Bigr) ds. 
% \eqno (2.13) $$
% }
% \smallskip
% </latex>

%%
% <latex>
% Equation (2.13) has an intuitive interpretation.  We know
% from Theorem 2.2 that the influence of an initial condition in
% the homogeneous equation (2.5) is $y_0^{} \exp(\int_0^t a(s) ds).$
% The idea behind (2.13) is that at each time $s$, the right-hand
% side $g(s)$, as it were, ``injects a small amount of initial condition''
% at that point.  Each such injection produces a contribution for
% $t>s$, and the second integral in (2.13) adds up those contributions.
% So inhomogeneous problems are like homogeneous ones, but with lots
% of little initial conditions --- a continuum of initial
% conditions --- along the way.\footnote{This idea can be made
% precise by the use of the Dirac delta function, though we shall not
% do that in this book.  Another language used by engineers calls
% the influence of a signal injected at a point the
% associated {\em impulse response.}}  This way of thinking leads to
% the method known as {\em variation of constants} or
% {\em variation of parameters,} which can be used
% to give a different proof of Theorem 2.3 and also applies
% to ODE\kern .5pt s of higher order.
% </latex>

%%
% To illustrate these developments, let us consider an IVP that looks a bit
% like the first nontrivial example of this chapter, (2.7).  Instead of
% taking $\sin(t^2)$
% as an oscillating coefficient on the $y$ term, we put it as an
% inhomogeneous forcing function on the right-hand side,
% $$ y'+ y = \sin(t^2) ,
% \quad t\in [\kern .3pt 0,8\kern .3pt ], \quad y(0) = 0. \eqno (2.14) $$
% Here is the solution, a curve that decays toward zero 
% while being forced alternately up and down.
L = chebop(0,8); L.lbc = 0; L.op = @(t,y) diff(y) + y;
t = chebfun('t',[0 8]); g = sin(t^2); y = L\g; plot(y,CO,ivp)
title('Fig.~2.4.~~Smooth inhomogeneous ODE (2.14)',FS,11)
%%
% <latex> \vskip 1.02em </latex>

%%
% As with the transition from (2.7) to (2.8), we can see the
% same effect more cleanly if we replace $\sin(t^2)$ by
% $\hbox{sign}(\sin(t^2))$,
% $$ y'+ y = \hbox{sign}(\sin(t^2)) ,
% \quad t\in [\kern .3pt 0,8\kern .3pt ], \quad y(0) = 0. \eqno (2.15) $$
%%
% <latex> \vskip -1.02em </latex>
L.op = @(t,y) diff(y) + y; g = sign(sin(t^2));
y = L\g; plot(y,CO,ivp)
title('Fig.~2.5.~~Nonsmooth inhomogeneous ODE (2.15)',FS,11)
%%
% <latex> \vskip 1.02em </latex>
%%
% <latex>
% \noindent
% Everywhere on this ``Sydney Opera House'' 
% there is exponential decay towards~$0$,
% though after the first few time units, the amplitude is small
% enough that the curve is dominated by the right-hand side,
% not the decay.
% </latex>

%%
% Here is another example.  If $g(t)=0$, the IVP
% $$ y' - \cos(t) = -10(y-\sin(t)) + g(t) ,
% \quad t\in [\kern .3pt 0,15], \quad y(0) = 0 \eqno (2.16) $$
% has solution $y(t) = \sin(t)$, as can be directly verified.
% Suppose now we introduce a forcing function $g$ that consists of a
% train of upward impulses located where $t$ is close to an
% odd integer.  Sydney Opera House turns into Batman.
L = chebop(0,16); L.op = @(t,y) diff(y) - cos(t) + 10*(y-sin(t));
L.lbc = 0; t = chebfun('t',[0 16]);
g = 10*(abs((t+1)/2-round((t+1)/2))<.05);
y = L\g; plot(y,CO,ivp), ylim([-2 2])
title('Fig.~2.6.~~Forcing by discontinuous impulses (2.16)',FS,11)
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% We mentioned before Theorem 2.3 that although the method
% of integrating factors provides a general formula for
% finding a particular solution of a
% first-order linear scalar inhomogeneous IVP,
% in many cases a simpler method is available.
% This is the {\bf method of undetermined coefficients,}
% and it consists of guessing the form of the solution,
% then substituting to find coefficients.\footnote{Some
% textbooks call it the
% {\em method of judicious guessing.}}  Often this
% idea works easily when the right-hand side contains 
% exponentials, because exponentials are
% preserved under differentiation.  Sines, cosines, and
% polynomials in the right-hand side are also often treatable
% in this way.  (The method is not restricted to first-order
% equations.)
% </latex>

%%
% For example, suppose we have the problem
% $$ y' + y = \exp(3\kern .2pt t) . \eqno (2.17) $$
% Knowing that differentiation preserves a 
% term involving $\exp(3\kern .2pt t)$, we consider the trial solution
% $$ y(t) = A\exp(3\kern .2pt t).  $$
% Inserting this in (2.17) gives
% $$ (3A + A)\exp(3\kern .2pt t) = \exp(3\kern .2pt t), $$
% from which we see that a particular solution of (2.17) is
% $$ y_{\rm p}(t) = \textstyle{1\over 4}\exp(3\kern .2pt t).  $$
% The general solution of (2.17) is accordingly
% $$ y(t) = \textstyle{1\over 4}\exp(3\kern .2pt t) + C \exp(-t). \eqno (2.18)  $$

%%
% As another example, consider the equation
% $$ y' + t y = t \exp(t^2). \eqno (2.19) $$
% The experienced eye will note that differentiating $w(t) = a \exp(t^2)$
% gives $w' = 2\kern .3pt t w$, so $w$ will satisfy (2.19) if
% $2\kern .3pt tw + tw = (t/a)w$, that is, $a = 1/3$.  Thus $\exp(t^2)/3$ is 
% a particular solution, and the general solution is
% $$ y(t) = {1\over 3} e^{t^2} + C\kern -.2pt e^{-t^2/2} . \eqno (2.20) $$
% Further examples of the method of undetermined coefficients
% are explored in Exercise 2.2.

%%
% <latex>
% For equations like these that are simple enough to solve exactly,
% an alternative method may be to do it in an automated way on the computer.
% If you type certain problems into
% WolframAlpha{\small\textsuperscript{\textregistered}}, the solution appears
% quickly.  Such an approach might succeed for many of the exercises
% to be found in elementary ODE textbooks, though it will be less
% successful for the higher-order, nonlinear, and behavioral investigations
% that are the bigger part of this field --- let alone for conceptual
% understanding.
% </latex>

%%
% <latex>
% Theorem 2.2 concerns the special case of Theorem 2.3 in which the problem
% is homogeneous, i.e., the right-hand side is zero.  Another important
% special case occurs when
% the problem is autonomous, with no explicit dependence
% on $t$.  Here is a theorem recording the solution in that case.
% </latex>

%%
% <latex>
% \smallskip
% {\em
% {\bf Theorem 2.4.  Solution of first-order linear scalar autonomous
% IVP (\textsf{\textbf{FLAShI}}).}
% The problem
% $$ y'-a y = g, \quad y(0) = y_0^{}, \eqno (2.21) $$
% where $y_0^{}$, 
% $a$, and $g$ are constants, has the unique solution
% $$ y(t) \,=\, y_0^{} e^{at}  + {g\over a}\left[ e^{at}-1\right],
% \eqno (2.22) $$
% or\/ $y(t) = y_0^{} + g\kern .3pt t$ if $a=0$.
% }
% \smallskip
% </latex>

%%
% <latex>
% \begin{center}
% \hrulefill\\[1pt]
% {\sc Application: elimination of caffeine from the bloodstream}\\[-3pt]
% \hrulefill
% \end{center}
% </latex>

%%
% <latex>
% If you drink a cup of coffee or a glass of wine, the body absorbs
% a dose of caffeine or alcohol that takes some time to clear away.
% The details of how this happens involve a complicated
% interplay of many organs and processes, but a differential
% equation model may capture the overall behavior.  Here is 
% a model of the elimination of caffeine adapted from
% R. Newton, et al., 
% ``Plasma and salivary pharmacokinetics of caffeine in man,''
% {\em European Journal of Clinical Pharmacology} 21 (1981), pp.~45--52.
% It falls in the category of models known as {\em first-order
% pharmacokinetics}.
% </latex>

%%
% The essential point is that to a reasonable approximation, when
% you're not drinking more coffee,
% the caffeine level $c(t)$ in your blood is governed by the equation
% $$ c'=-k c, $$
% where $k$ is a positive rate constant.
% This means that $c(t)$ will decay exponentially, and the decay
% rate is often expressed as a half-life $t_{1/2}^{}$, defined by
% $$ e^{-k \kern .5pt t_{1/2}^{}} = {1\over 2}, \qquad
% t_{1/2}^{} = {\log(2)\over k}. $$

%% 
% <latex>
% Experiments show 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~$\mu{\rm g}$/mL in the blood plasma.
% This boost is followed by first-order 
% kinetics with a half-life $t_{1/2}$ of about 6 hours,
% although the rate can vary a great deal from person to person.
% Here we compute the rate constant $k$ from the half-life $t_{1/2}$ 
% and then define an ODE accordingly, with $t$ representing
% time in hours over a 24-hour period:
% </latex>
t12 = 6; k = log(2)/t12; L = chebop(@(t,c) diff(c)+k*c,[-2,24]);

%% 
% <latex>
% \noindent
% We will assume that 300 mg of caffeine will be ingested
% over half an hour, increasing the caffeine concentration
% at a rate of 16 $(\kern .7pt\mu{\rm g}/{\rm mL})/{\rm hr}$.  
% Suppose coffee is consumed at 7:00, 10:00, and 15:00.
% Here is the intake schedule with
% time measured from the first cup.
% </latex>
t = chebfun('t',[-2,24]);
coffee = @(t0) 16*(t > t0)*(t < t0+0.5);
intake = coffee(0) + coffee(3) + coffee(8);
plot(intake,'k','jumpline','-'), axis([-2 24 -5 20])
xlabel('time since first cup (hours)',FS,9)
title(['Fig.~2.7.~~Caffeine intake rate, ' ...
  '($\kern .7pt\mu{\rm g}$/mL)/hr'],IN,LT,FS,11)
%%
% <latex> \vskip 1.02em </latex>

%% 
% <latex>
% \noindent
% Here is the caffeine level during the 24-hour period.
% </latex>
L.lbc = 0; c = L\intake;
hold on, plot(c,CO,ivp), hold off
title(['Fig.~2.8.~~Caffeine concentration in the blood, ' ...
       '$\mu{\rm g}$/mL'],IN,LT,FS,11)
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent
% As you can see, 24 hours is not long enough to 
% clear the caffeine from the bloodstream.
% For the case of three cups per day repeated periodically, see
% Exercise~19.7.
% </latex>
%%
% <latex>
% \smallskip
% {\sc History.}  Separation of variables goes
% back to Leibniz and Johann Bernoulli in the 1690s.  Integating factors 
% came a few years later with Euler and Lagrange.
% \smallskip
% </latex>

%%
% <latex>
% {\sc Our favorite reference.}  It is hard to find much to say about
% first-order 
% scalar linear ODE\kern .5pt s.  Noting, however, that a theme in this subject
% is time scales of growth and decay processes, we draw
% attention to the fascinating {\em Time in Powers of Ten: Natural
% Phenomena and their Timescales} by 't Hooft and Vandoren,
% World Scientific, 2014.
% \smallskip
% </latex>

%%
% <latex>
% \def\equals{\kern 1pt =\kern 1.5pt}
% \begin{displaymath}
% \framebox[4.7in][c]{\parbox{4.5in}{\vspace{2pt}\sl
% {\sc Summary of Chapter 2.}  
% A first-order linear scalar 
% ODE has a one-dimensional affine space of solutions of the
% form $y_{\rm p} + Cy_{\rm h}^{}$, and
% if an initial condition is specified, it has the unique solution
% given by Theorem\/ $2.3$, which can be derived by
% multiplying by an integrating factor.
% In the special case where the
% problem is homogeneous, we have $y_{\rm p}=0$,
% and the solution to the IVP is given by Theorem\/ $2.2$, which
% can be derived by separation of variables.
% \vspace{2pt}}}
% \end{displaymath}
% </latex>
 
%%
% <latex>
% \small\parindent=0pt\parskip=1pt
% {\em Exercise $2.1$.  Separation of variables.} 
% Use separation of variables to find general solutions
% to {\em (a)} $y' = e^{y+t}$, {\em (\kern .7pt b)} $y' = t\kern .3pt y+y+t+1$,
% {\em (c)} $y' = (t^2+2)/y$.
% Confirm your answers with 
% WolframAlpha or some other computational tool.
% Which of these equations are linear?
% \par
% {\em Exercise $2.2$.  Method of undetermined coefficients.}
% Use the method of undetermined coefficients to find general
% solutions to
% {\em (a)} $y' = y + e^{\kern .3pt t}$ (try $y = a\kern .5pt t\kern .5pt e^{\kern .3pt t}$),
% {\em (\kern .7pt b)} $y' = y + t\sin(t)$ (try $y = a\kern .5pt \sin(t)
% + b\kern .7pt t\sin(t) + c\kern .3pt\cos(t) + d\kern .7pt t\cos(t)$),
% {\em (c)} $y' = 2y + e^{\kern .3pt t} + 1$,
% {\em (d)} $y' = 1 - 2\kern .3pt t\kern .3pt y$ {\em (Dawson's integral)}.
% Confirm your answers with 
% WolframAlpha or some other computational tool.
% \par
% {\em Exercise $2.3$.  Interchanging variables to make
% a problem linear.} 
% {\em (a)} Although the differential equation $y' = y/(t+y)$ is nonlinear,
% show that it becomes linear if it is rewritten as an
% equation for $dt/dy$ rather than $dy/dt$.  Solve this linear
% equation analytically by determining an appropriate integrating
% factor, and thereby also solve the original nonlinear equation.
% {\em (\kern .7pt b)} If $y(0) = 1$, what is $y(1)$?  Find the solution numerically or
% analytically.
% (An analytical solution involves a special function
% known as the Lambert W-function.)
% \par
% \par
% {\em Exercise $2.4$.  Choosing a coefficient.} 
% Suppose $y_0^{}=1$ in (2.5).  Give a function
% $a(t)$ such that the solution $y(t)$ has $y(1)=2$.
% \par
% {\em Exercise $2.5$.  No changes of sign.} 
% Consider an IVP (2.5) for which $y_0^{}$£ and
% $a(t)$ are real (i.e., not complex).  Show that the
% solution $y(t)$ is positive for all $t$, negative
% for all $t$, or zero for all $t$.  What's the
% strongest analogous result you can state in the
% case where $a(t)$ is permitted to be complex?
% \par
% {\em \underline{Exercise $2.6$}.  Local extrema of an oscillation.}
% Let $t_{50}^{}$ denote the point where the solution of
% $y' = -\cos(10/(1-t))$, $y(0) = 1$, achieves its 50th local
% maximum (in Chebfun, {\tt [a,b] = max(y,'local')}). {\em (a)} Determine
% $t_{50}^{}$ and $y(t_{50}^{})$ numerically, and plot $y(t)$ for
% $0\le t \le t_{50}^{}$.  {\em (\kern .7pt b)} Confirm the the exact value of
% $t_{50}^{}$ analytically.
% \par
% {\em \underline{Exercise $2.7$}.  Adjusting Batman's ears.}
% {\em (a)} Use \verb|max(y{6,8})| to calculate the maximum value of $y(t)$
% in the interval $[6,8\kern .3pt ]$ for the problem of Fig.~2.6.
% {\em (\kern .7pt b)} What happens to the plot, and to this maximum value, if the
% impulse is made 3 times as wide with $1/3$ the amplitude?
% {\em (c)} What if it is 1/3 as wide with 3 times the amplitude?
% \par
% {\em \underline{Exercise $2.8$}.  Temperature of a dead body.}
% It was observed in 1894 that a human body after death cools at a rate
% that is ``nearly proportional to the difference between the body and the
% surroundings.'' (This heat transfer principle is known as Newton's law of cooling.
% The quote comes from de Saram, Webster, and Kathirgamatamby, ``Post-mortem
% temperature and the time of death,'' {\em Journal of Criminal Law
% Criminology and Police Science} 64 (1955), 562--577.)
% Let's assume that the cooling rate is $-\beta\kern .3pt 
% \theta(t)$, where $\theta(t)$ is the difference between body and
% surrounding temperature, and $\beta$ is an empirical constant. 
% De Saram et al.\ measured the temperatures of 41 executed prisoners
% to test this model.
% In one case the body temperature was $97.8^\circ$F at 11 AM and $96.2^\circ$F
% at 1 PM.\ \ The room temperature was held at $86.4^\circ$F.\ \ {\em (a)}
% Use the temperature readings to
% find a numerical value for $\beta$.\ \ {\em (\kern .7pt b)} By assuming
% that at the time of
% death the body temperature was $98.6^\circ$F, determine an approximate
% time of death.
% \par
% {\em \underline{Exercise $2.9$}. Heaviside function.}
% Many of the examples of this chapter involve ODE\kern .5pt s forced by
% discontinuous right-hand sides.  Another way to formulate such
% problems is with the {\em step function} or {\bf Heaviside function}
% $H(t)$, which takes the value $0$ for $t<0$ and $1$ for $t>0\kern .5pt;$
% the value at $t=0$ is $0.5$.
% Execute the instructions \verb|L = chebop(0,2),|
% \verb|L.op = @(t,y) diff(y)+y,| \verb|L.lbc = 1,| 
% \verb|t = chebfun('t',[0,2]),| \verb|f = heaviside(t-1)|,
% \verb|y = L\f|.\ \ Write down the IVP that is being solved here,
% plot the solution $y$ just computed, and derive an exact formula
% for this function.  How accurate is the computed value $y(2)\kern .5pt ?$
% \par
% {\em \underline{Exercise $2.10$}.  An ODE from Newton (\/$1671$) and Taylor
% series approximations.}
% One of the first IVPs ever considered was 
% the equation $y'=1-3\kern .15pt t+y+t^2+t\kern .3pt y$
% with initial condition $y(0)=0$, presented by Isaac Newton in 1671.
% Newton solved this by using what we now call a Taylor series,
% obtaining the representation
% $y(t)=t-t^2+t^3/3-t^4/6+t^5/30-t^6/45+\cdots.$
% What is the maximum difference between this 6-term approximation and
% the true solution on the intervals {\em (a)} $[\kern .5pt 0,0.5],$
% {\em (\kern .7pt b)} $[\kern .5pt 0,1],$
% {\em (c)} $[\kern .5pt 0,2\kern .3pt],$ and
% {\em (d)} $[\kern .5pt 0,4]\kern.7pt?$\ \   Give the numbers
% and also plot the absolute value of
% the error as a function of $\kern .8pt t$ on a log-log scale.
% Comment on the plot.
% \par
% {\em \underline{Exercise $2.11$}.  Equation with sensitive solutions.}
% Consider the equation $y' + t\kern .3pt y = f(t)$ for $t\in [-4,4]$ with $y(-4)=0$.
% {\em (a)} What is $\max_{t\in[-4,4]}^{} y(t)$ if $f(t) = \sin(t)\kern .5pt?$
% What does this change to if $f(t) = \sin(0.85 t)\kern .5pt?$
% {\em (\kern .7pt b)} What term in the formulas of Theorem~2.3 makes it possible
% for these numbers to vary so greatly?
% \par
% {\em \underline{Exercise $2.12$}.  Thiele's equation for life insurance.}
% Simple life insurance is purchased for a length of time $T$ and
% costs the insured party a fixed premium $P$ per year.
% If the insured dies during the term of the policy, the insurer must pay a
% benefit of $S$. Otherwise, the insured receives nothing. The insurer
% is required to keep money in reserve
% for this policy in order to be able
% to pay out all the claims likely to result from a pooled group of
% individuals. This is done via the {\em Thiele differential equation,}
% first derived in 1875 and published in 1910.
% Let $V(t)$ for $0\le t \le T$ be the amount of reserve
% needed for a policy purchased at time $t=0$. Thiele's equation is
% $V'=  P + \delta V(t) - \mu(t) (S-V(t)),$
% where $\delta$ is the {\em force of interest} (the interest
% rate) and $\mu(t)$ is the {\em force of mortality} (the
% probability of a person dying per unit time). When the policy
% expires, no reserve is needed, so $V(T)=0$.\footnote{The
% property of a time-dependent equation being governed
% by a {\em final condition} rather than an initial condition
% arises commonly in financial modelling.  The famous example
% involving a PDE is the Black--Scholes equation.}
% {\em (a)}
% Plot the solution $V(t)$
% for $\mu(t) = 0.007(t+5)$, $\delta = 0.03$, $P = 800,$
% $S = 1e6,$ and $T = 25.$
% {\em (\kern .7pt b)} What is the maximal value of $V(t)\kern .5pt$?  Is it
% less than or equal to $S$\kern .5pt?  Interpret this inequality
% financially. {\em (c)}  Assuming $\delta \ge 0$,
% prove that any solution of the
% ODE problem will satisfy this inequality.
% \par
% {\em Exercise $2.13$.  Without the method of undetermined coefficients.}
% Solve (2.17) using Theorem~2.3.
% </latex>
