%% 8. Resonance
% <latex>
% \setcounter{page}{88}
% </latex>

%%
% Certain systems have one or more natural frequencies at
% which they oscillate.
% If you force such a system by an input that oscillates
% at close to a natural frequency,
% the response may be very large in amplitude.
% In this chapter we explore this phenomenon.

%%
% <latex>
% The basic idea is linear, autonomous, and inhomogeneous.
% Following (4.3), consider the ODE of simple harmonic motion,
% $$ y'' + \omega^2 y = f(t), \eqno (8.1) $$
% where $\omega$ is a real constant.
% One application of this equation is to a linear pendulum, where
% $y(t)$ represents the (small) angle from the vertical
% at time $t$.
% Here $\omega^2$ takes the value $g/L$, where
% $g$ is the earth's gravitational acceleration
% and $L$ is the length of the pendulum.
% Let us imagine that the pendulum is a girl
% on a playground swing.
% The issue to be examined is the response of the swing to
% the forcing function $f$, which we can interpret
% as the acceleration introduced by the girl's mother, who is
% pushing.
% </latex>

%%
% <latex>
% There is really just one bit of
% physics in (8.1), and that is that the associated homogeneous equation
% $$ y'' + \omega^2 y = 0  \eqno (8.2) $$
% has solutions $\sin(\omega\kern .3pt t)$
% and $\cos(\omega\kern .3pt t)$.  This is what we mean when we
% say that the {\bf natural frequency} of (8.1) is
% $\omega$.\footnote{As in Chapter 4, what we call a frequency could more
% fully be called an angular frequency.} 
% To focus on the simplest possible setting, let us
% look at solutions $y(t)$ driven by
% the sinusoidal forcing function $f(t) = \sin(\nu\kern .3pt t)$ for some
% $\nu \ne \omega$,
% $$ y'' + \omega^2 y = \sin(\nu\kern .3pt t).  \eqno (8.3) $$
% As a reminder of this not very standard notation we note
% \begin{displaymath}
% \framebox[3.3in][c]{\parbox{3.1in}{\vspace{2pt}\sl
% $\omega =$ {\it resonant frequency,} $\quad
% \nu =$ {\it forcing frequency.}
% \vspace{2pt}}}
% \end{displaymath}
% We can solve (8.3) analytically.  Inserting
% the trial solution $y(t) = A\sin(\nu\kern .3pt t)$ gives
% $$ (-\nu^2 + \omega^2)y = {y\over A}, $$
% which implies that a particular solution is
% $$ y_{\rm p}^{} (t) = {\sin(\nu\kern .3pt t)\over \omega^2 - \nu^2} . $$
% The general solution is accordingly
% $$ y(t) = {\sin(\nu\kern .3pt t)\over \omega^2 - \nu^2} 
% + B\sin(\omega\kern .3pt t) + C\cos(\omega\kern .3pt t) \eqno (8.4) $$
% for constants $B$ and $C$.
% Note that this is a superposition of sine/cosine waves of
% two different frequencies, so in general, $y(t)$ is not periodic.
% </latex>

%%
% For example, suppose we take $y(0) = y'(0) = 0$, giving the IVP 
% $$ y'' + \omega^2 y = \sin(\nu\kern .3pt t), \quad t\ge 0,
% ~ y(0)=y'(0) = 0.  \eqno (8.5) $$
% Choosing $B= -(\nu/\omega )/(\omega^2-\nu^2)$ and
% $C=0$ in (8.4) to match the initial conditions, we get the solution
% $$ y(t) = {\sin(\nu\kern .3pt t) - (\nu/\omega ) \sin(\omega\kern .3pt  t)
% \over \omega^2 - \nu^2} . \eqno (8.6) $$
% Here is a calculation for $t\in [\kern .3pt 0,200\kern .3pt]$ with
% $\omega =1$ and $\nu=0.7$. 
ODEformats
L = chebop(0,200); L.lbc = [0;0]; L.op = @(t,y) diff(y,2) + y;
t = chebfun('t',[0 200]); f = sin(0.7*t);
subplot(2,1,1), plot(f,'k'), ylim([-2 2])
title('Fig.~8.1.~~Forcing function $f(t) = \sin(0.7t) $',FS,11) 
y = L\f; subplot(2,1,2), plot(y,CO,ivp)
title('Response $y(t)$, resonant frequency $\omega=1$',FS,11) 
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent
% This solution is an incoherent signal of no great interest.
% On the other hand, suppose we take $\nu = 0.95$,
% a value much closer to $\omega$.
% </latex>
f = sin(0.95*t); subplot(2,1,1), plot(f,'k'), ylim([-2 2])
title(['Fig.~8.2.~~Forcing function $f(t) = \sin(0.95t) $'],FS,11) 
y = L\f; subplot(2,1,2), plot(y,CO,ivp), ylim([-30,30])
title('Response $y(t)$, resonant frequency $\omega=1$',FS,11) 
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent
% Now the response shows great regularity
% and a high amplitude, about $20$, which
% builds up over an interval of $60$ time units.  This is
% {\bf resonance,} which we
% can define as the pumping of energy into or out of a system by
% a driving function oscillating at close to a natural frequency.
% The mother is pushing the swing at close to its natural rate.
% The growth in amplitude occurs so long as her
% input is in advance of the phase
% of the growing oscillation.  Eventually, however, after around
% time $t=60$, the impulses lag behind the phase of the swing and
% she starts extracting energy.
% The cycle goes on in the effect known as {\em beating,}
% with alternating long
% stretches of energy injection and energy extraction.
% (No actual mother, of course, would be so mechanical.)
% </latex>

%%
% <latex>
% All of the above is mathematically correct, and an important
% base case on which to build
% one's understanding of resonance, but it is physically
% unrealistic.  If an autonomous system is forced by a periodic signal
% $f(t) = \sin(\nu\kern .3pt t)$, then surely 
% we would expect it to have a periodic
% solution $y(t)$ with the same frequency,
% at least for large $t$, after the effect
% of the initial conditions has died away.  Why hasn't
% this happened?  The problem is
% that (8.3) includes no damping, so the effect of the
% initial conditions never dies away.  We can see this
% in formulas (8.4) and (8.6), where $B$ and $C$ take values
% determined by the initial conditions and the
% associated $\sin(\omega\kern .3pt t)$ and $\cos(\omega\kern .3pt  t)$
% terms persist forever.
% </latex>

%%
% The picture changes fundamentally if
% we add a small amount of damping, generalizing (8.3) as in (4.10) to
% $$ y'' + \varepsilon\kern .2pt  y' + \omega^2 y = \sin(\nu\kern .3pt t)  \eqno (8.7) $$
% for some small $\varepsilon>0$.  Here is the first example
% again, but now, with two response curves shown: the first for (8.3)
% without damping, the same as before,
% and the second for (8.7) with damping coefficient $\varepsilon = 0.04$.
L2 = chebop(0,200); L2.lbc = [0;0];
L2.op = @(t,y) diff(y,2) + 0.04*diff(y) + y;
f = sin(0.7*t); clf, subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title(['Fig.~8.3.~~Undamped and damped responses ' ...
       'to $\sin(0.7t)$'],FS,11) 
y = L\f; subplot(3,1,2)
plot(y,CO,ivp), ylim([-5 5]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = L2\f; subplot(3,1,3), plot(y,CO,ivp), ylim([-5 5])
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% With damping, it is clear that as $t\to\infty$, the solution
% approaches a periodic form with frequency $\nu$.
% By appropriate changes in the earlier formulas, we can work
% out the details analytically.  It is tempting to start with the
% trial solution $y(t) = A\sin(\nu\kern .3pt t)$ again, but this will not work
% because the $y'$ term will introduce a cosine.
% We could get around this with a trial solution containing both
% a sine and a cosine, but it is algebraically simpler to
% combine the two by introducing complex exponentials.
% Thus we replace (8.7) by
% $$ y'' + \varepsilon y' + \omega^2 y = \exp(i\kern .3pt\nu\kern .3pt t), \eqno (8.8) $$
% and the imaginary part of the solution will correspond to the
% solution (8.6).  Inserting 
% $y(t) = A\exp(i\kern .3pt\nu\kern .3pt t)$ gives
% $$ (-\nu^2 +i\kern .3pt\nu \varepsilon + \omega^2)y = {y\over A}, $$
% which implies that a particular solution is
% $$ y_{\rm p}^{} (t) = {\exp(i\kern .3pt\nu\kern .3pt t)\over \omega^2 
% + i\kern .3pt\nu \varepsilon- \nu^2} . \eqno (8.9) $$
% From equation (4.13) in Chapter 4, it can be deduced that the
% general solution to (8.8) will be a linear combination of this
% function $y_{\rm p}^{}(t)$
% with terms decaying exponentially at the rate $\exp(-\varepsilon\kern .5pt t/2)$.
% This confirms that the general solution will be asymptotically periodic
% as $t\to\infty$.
% </latex>

%%
% Now we add damping to the second experiment, with $\nu=0.95$.
% Again the response settles down to a periodic form, with somewhat
% smaller amplitude than before.
f = sin(0.95*t); subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200);
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title(['Fig.~8.4.~~Undamped and damped responses ' ...
       'to $\sin(0.95t)$'],FS,11) 
y = L\f; subplot(3,1,2)
plot(y,CO,ivp), ylim([-30 30]), set(gca,XT,0:20:200);
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = L2\f; subplot(3,1,3), plot(y,CO,ivp), ylim([-20 20])
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% The relationship between forcing and response in resonance has an element
% of phase as well as amplitude.  In the trio of images above, say,
% take a look at the forcing and response curves at the final
% time $t=200$.
% We see that all three curves have a maximum near this point,
% reflecting the fact that in (8.4), since $\nu<\omega $,
% the denominator is positive, and in (8.9) it is nearly
% positive though slightly complex.  Thus the input and the
% responses are {\em in phase.}  Suppose we now change
% $\nu$ to $1.05$, a value equally close to $\omega $ but
% larger rather than smaller.  Now the denominators of (8.4) and
% (8.9) are negative and nearly negative, respectively,
% and looking near $t=200$ in the figure below confirms that the
% forcing and response functions have moved out of phase by an 
% angle of $\pi$, that is, 180 degrees.  This is a basic difference
% in the physics of the two kinds of resonance phenomena.
% </latex>
f = sin(1.05*t); clf, subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title(['Fig.~8.5.~~Responses to $\sin(1.05t)$, ' ...
       'with 180 degree phase shift'],FS,11) 
y = L\f; subplot(3,1,2)
plot(y,CO,ivp), ylim([-25 25]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = L2\f; subplot(3,1,3), plot(y,CO,ivp), ylim([-25 25])
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% We can summarize the phase lag situation (for
% sufficiently small damping $\varepsilon$) according to
% whether the forcing frequency is lower or higher than
% the resonant frequency:
% \begin{displaymath}
% \framebox[3.0in][c]{\parbox{2.8in}{\vspace{2pt}\sl
% $\nu < \omega{:}$ {\it no phase lag,} $\quad
% \nu >\omega {:} ~180^\circ$ {\it phase lag.}
% \vspace{2pt}}}
% \end{displaymath}
% \noindent For more precision, see Exercise 8.7.
% </latex>

%%
% <latex>
% As $\nu$ gets closer to $\omega $, the maximum amplitude
% of $y(t)$ for the undamped equation (8.3)
% increases to $\infty$, and so does the
% time scale over which it achieves that maximum.
% If $\nu = \omega $ exactly, the forcing
% and the oscillation are synchronized forever.  Energy keeps
% getting pumped into the system, and the amplitude grows without limit.
% This unbounded growth for undamped oscillation corresponds to a singularity
% in the formulas (8.4) and (8.6), but not in the IVP itself or
% its solution, which shows simply a linear increase with $t$.
% In the damped cases, the growth asymptotes to a fixed
% amplitude.
% </latex>
f = sin(t); clf, subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title(['Fig.~8.6.~~Responses to $\sin(t)$, ' ...
       'with 90 degree phase shift'],FS,11) 
y = L\f; subplot(3,1,2)
plot(y,CO,ivp), ylim([-120 120]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = L2\f; subplot(3,1,3), plot(y,CO,ivp), ylim([-50 50])
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% The linearly growing solution to an undamped resonant system
% forced at the resonant frequency is called a
% {\bf secular solution}.  In this case we can derive that
% the exact solution of (8.5) is
% $$ y(t) = {-t \cos (\omega \kern .5pt t)\over 2\kern .5pt \omega^2}
% + {\sin(\omega\kern .3pt t)\over 2\kern .5pt\omega^3} ; \eqno (8.10) $$
% the term involving $t\cos(\omega\kern .3pt t)$ is the secular one.
% Secular terms arise whenever an ODE has an inhomogeneous
% forcing function that is itself a solution to the homogeneous problem.
% </latex>

%%
% What about the phase lag in this special situation
% $\nu = \omega $?  Looking at the figures near
% the final time $t=200$, we see that as one might guess, the lag is
% now midway between the two cases
% we have seen before, namely
% one quarter of a wavelength, an angle of $\pi/2$ or
% $90^\circ$.  We can confirm this algebraically
% by noting that in the formula (8.10),
% although the forcing function is the sine,
% the secular term of the response involves the negative of the cosine.
% In a case with damping, the $90^\circ$ lag comes from the
% $i$ in the denominator of (8.9).

%%
% The discussion so far has concerned the response of (8.1) or
% its damped cousin to a pure sine
% wave, but of course, not every forcing function will be so simple.
% More generally, if $f$ is a function that looks approximately
% like a sine wave for a certain range of values of $t$, we may
% expect to see approximately corresponding behavior for a time.  Here is an
% experiment to illustrate.  Consider
% $$ f(t) = \sin ((t/100)\cdot t), $$
% a function whose frequency starts at $\nu=0$ for
% $t=0$ and then increases linearly to $\nu = 4$ at $t=200$ since
% $(t^2/100)' = t/50$.
% (In Chapter 17 we will do a number of such experiments
% with parameters slowly varying with $t$.)
% The response $y(t)$ shown in Figure 8.7
% does nothing very interesting 
% until near $t=50$, when it grows to a considerable amplitude
% due to resonance.  Soon the forcing drifts out of tune again,
% after which no further significant transfer of energy from
% the forcing function takes place.
% The undamped response curve shows a permanent record of the brief
% moment of resonance near $t=50$, and the damped response curve
% dies away slowly on the time scale $\exp(-\varepsilon\kern .5pt t/2)$.
f = sin((t/100)*t); clf, subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title('Fig.~8.7.~~Responses to $\sin((t/100)t)$',FS,11) 
y = L\f; subplot(3,1,2)
plot(y,CO,ivp), ylim([-15 15]), set(gca,XT,0:20:200)
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = L2\f; subplot(3,1,3), plot(y,CO,ivp), ylim([-15 15])
%%
% <latex> \vskip 1.02em </latex>

%%
% This chapter has focused on linear equations, because the 
% basic mechanism of resonance is linear.
% However, resonance
% occurs in nonlinear systems too.  For example, generalizing
% (8.7) in the case $\omega =1$,
% consider the nonlinear pendulum equation
% $$ y'' + \varepsilon y' + 45\sin(y/45) = \sin(\nu\kern .3pt t),
% \eqno (8.11) $$
% where the constant $45$ has been chosen arbitrarily,
% corresponding to a rather weak nonlinearity. 
% Here are the undamped and damped solutions (with $\varepsilon = 0.04$
% as usual) in the same format as before.
N = chebop(0,200); N.lbc = [0;0];
N2 = chebop(0,200); N2.lbc = [0;0];
N.op = @(t,y) diff(y,2) + 45*sin(y/45);
N2.op = @(t,y) diff(y,2) + .04*diff(y) + 45*sin(y/45);
f = sin(0.95*t); clf, subplot(3,1,1)
plot(f,'k'), ylim([-2 2]), set(gca,XT,0:20:200);
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.04; set(gca,'pos',pp)
title(['Fig.~8.8.~~Nonlinear responses to $\sin(0.95t)$, ' ...
       'eq. (8.11)'],FS,11) 
y = N\f; subplot(3,1,2)
plot(y,CO,ivpnl), ylim([-40 40]), set(gca,XT,0:20:200,YT,-40:40:40);
set(gca,XTL,{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '})
pp = get(gca,'pos'); pp(2) = pp(2)-.02; set(gca,'pos',pp)
y = N2\f; subplot(3,1,3), plot(y,CO,ivpnl), ylim([-40 40])
set(gca,YT,-40:40:40)
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent
% Note that in comparison to Figure 8.4, the amplitude and
% the time scale have increased.  This is because in this example,
% nonlinearity has weakened the restoring force, 
% decreasing the natural frequency of
% the system, thereby bringing the forcing frequency closer to resonance.
% </latex>

%%
% <latex>
% \begin{center}
% \hrulefill\\[1pt]
% {\sc Application: moon, sun, and tides}\\[-3pt]
% \hrulefill
% \end{center}
% </latex>

%%
% Everybody knows that the moon causes the tides,
% with a further contribution from the sun.  But there are some
% surprises along the way related to the material of this chapter.

%%
% <latex>
% The resonant system here consists of the earth's oceans,
% and the forcing function consists
% of the gravitational force from the moon, whose direction
% changes as the earth turns.  With respect to a
% fixed point on Earth, the moon appears to go around about
% once every 24.8 hours.  This means the tidal forcing from
% the moon has a period of about $T = 12.4$ hours, since,
% as many books and web pages will tell you, the moon's
% gravity both pulls on the ocean nearest it more than on the earth
% below {\em and\/} pulls on the earth below more
% than on the ocean on the far side.
% So our forcing function, with time measured in hours, has frequency
% $\nu = 2\pi / T \approx 0.507$.  Here's a picture over
% 672 hours, i.e., four weeks.
% </latex>
t = chebfun('t',[0,672]);
Tmoon = 12.4; numoon = 2*pi/Tmoon;
f = cos(numoon*t); clf, plot(f,'k'), ylim([-2.5 2.5])
xlabel('$t$ in hours over a 4-week period',FS,9)
ylabel('forcing',FS,9)
title('Fig.~8.9.~~First approximation to tidal forcing',FS,11) 
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% There are two big day-to-day corrections to be added
% to this picture.  The first is the influence of the sun.
% As it happens, the
% gravitational force from the sun is about 180 times as big as that
% from the moon.  This big factor doesn't matter, however, since
% tides depend
% on gravity being stronger on one side of the earth than the
% other: what matters
% is the {\em gradient} of the gravitational force.  This is
% about twice as great for the moon as for the sun.  Moreover, the
% period associated with the sun's forcing is
% of course simply 12 hours, not 12.4.   The difference in periods
% causes a slow beating in and out of phase, giving a
% combined gravitational forcing from the moon and sun
% like this.
% </latex>
Tsun = 12; nusun = 2*pi/Tsun;
f = cos(numoon*t) + 0.46*cos(nusun*t);
plot(f,'k'), ylim([-2.5 2.5])
xlabel('$t$ in hours over a 4-week period',FS,9)
ylabel('forcing',FS,9)
title(['Fig.~8.10.~~Correction for the sun: ' ...
       'bigger forcing every 2 weeks'],FS,11) 
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent 
% When the moon is new or full, it is aligned with
% the sun (a configuration called {\em syzygy}) and
% we we have big {\em spring tides.}  A week later it
% is $90^\circ$ off and we have smaller {\em neap tides.}
% </latex>

%%
% The other big correction is the one that  makes
% tides alternate big-small-big-small.  This is caused
% by the fact that whereas the moon's orbit
% is close to the ecliptic (the plane of the solar system), the earth's
% orbit is tilted by $23\%$.  That means that if
% you live somewhere between the 
% equator and a pole, as the earth turns during the day, you may
% alternate between close to the ecliptic at one high of the
% gravitational forcing function and $90^\circ$ away at the next.
% So the forcing function near you looks more like this (the
% details will depend on latitude and season of the year).
f = .8*cos(numoon*t) + .2*cos(numoon*t/2) ...
    + .8*.46*cos(nusun*t) + .2*.46*cos(nusun*t/2);
plot(f,'k'), ylim([-2.5 2.5])
xlabel('$t$ (hours)',FS,9), ylabel('forcing',FS,9)
title('Fig.~8.11.~~Correction for tilting of Earth''s axis',FS,11) 
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% Figure 8.11 sketches half of the tide problem, the
% gravitational forcing.  (We've omitted longer time scale
% annual effects, as
% the earth moves around the sun, and also the variation in the
% moon's distance from the earth since its orbit
% is not a circle.)  The other half concerns
% the resonant response by the water on Earth.  The full details of
% this are very complicated,
% for the oceans have complicated boundaries.
% Nevertheless, we
% can see a part of the picture by ignoring the continents
% and imagining that the ocean is a uniform cover of the
% earth a few miles deep.
% What is the natural frequency of this system?  The answer is
% determined by how fast waves travel across the ocean --- not the
% little waves one might surf on, but the so-called {\em shallow-water waves}
% associated with tsunamis.  It turns out that these travel
% about half as fast as the earth rotates.  (It would be different
% if the ocean were deeper.)
% </latex>

%%
% <latex>
% So Earth's tides are in the regime $\nu > \omega$, where
% {\em the forcing frequency exceeds the resonant frequency}.
% This means that we can expect the tides to be about half a period
% out of phase with the moon.  Since the moon's forcing peaks
% not once but twice per day, this $180^\circ$ difference in
% mathematical phase corresponds to a $90^\circ$ difference in
% geometric orientation.  We can sketch it like this:
% </latex>
earth = chebfun('exp(1i*x)',[0 2*pi]);
fill(real(earth),1.2*imag(earth),[.42 .57 .84]), hold on
fill(real(earth),imag(earth),[.8 .8 .8])
moon = 6+.4*earth;
fill(real(moon),imag(moon),[.96 .95 .72]), hold on
text(0,-1.5,'Earth',FS,10,HA,CT)
text(-.8,1,'tidal bulge',FS,10,HA,RT)
text(6,-.7,'Moon',FS,10,HA,CT), axis equal, axis off
title(['Fig.~8.12.~~Tides on Earth, out of phase ' ...
       'with gravitational input'],FS,11)
%%
% <latex> \vskip 1.02em </latex>

%%
% <latex>
% \noindent
% Many of us have seen figures like this, perhaps even
% when we were teenagers first learning about the tides.  But the pictures
% usually show the bulges pointing in line with the moon, not at
% right angles!  That's correct in a certain static sense, as it conveys
% the underlying gravitational force, but it's wrong dynamically.
% </latex>

%%
% <latex>
% We hasten to emphasize that the actual behavior of tides on
% Earth is far more complex than Figure 8.12 and the discussion
% above recognize.  For example, the phase lag is diminished
% by damping, which is not negligible, and at high latitudes by
% the smaller distance around the globe, which brings the 
% natural frequency of oscillation close to the
% frequency of gravitational input.  Most importantly,
% we have ignored the continents completely, whose presence 
% changes the details in
% a manner that varies from place to place.
% See for example E. I. Butikov, A dynamical picture of the
% oceanic tides, {\em American Journal of Physics} 70 (2002),
% pp.~1001--1011.  Because of these effects, if you actually
% look at tide data to see whether reality better fits Fig.~8.12 or
% its opposite, you are likely to find that the data are
% all over the place.  See Exercise 8.4.
% </latex>

%%
% <latex>
% \smallskip
% {\sc History.}  It was Newton who figured out the fundamental dynamics of
% Earth's tides, in his {\em Principia,} as a consequence of the same
% law of gravity that explains orbits of planets around the sun.
% \smallskip
% </latex>

%%
% <latex>
% {\sc Our favorite reference.}  For a delightful tour of resonance
% and many other effects, check out
% E. J. Heller, {\em Why You Hear What You Hear: An Experiential
% Approach to Sound, Music, and Psychoacoustics,} Princeton
% University Press, 2013.  It is hard to read even a single page
% of Heller's book without learning something interesting.
% \smallskip
% </latex>

%%
% <latex>
% \begin{displaymath}
% \framebox[4.7in][c]{\parbox{4.5in}{\vspace{2pt}\sl
% {\sc Summary of Chapter 8.}   Resonance is the
% interaction between a system with a natural frequency of
% oscillation and external forcing at a nearby frequency.
% Over a period of oscillations, a great deal of energy
% can be injected into an oscillating system by this effect.
% If the damping is small,
% forcing at the resonant frequency introduces
% a phase shift of\/ $90$ degrees
% and forcing above the resonant frequency results in
% a phase shift of\/ $180$ degrees. In systems with
% damping, forcing by a periodic function of
% frequency\/ $\nu$ leads to a solution that approaches
% periodic form as\/ $t\to\infty$.
% \vspace{2pt}}}
% \end{displaymath}
% </latex>

%%
% <latex>
% \small\parindent=0pt\parskip=1pt
% {\em \underline{Exercise $8.1$}.  Exploiting resonance to increase amplitude.}
% For a given frequency $\nu$, consider the solution
% to $y'' + y = 1 - \cos(\nu\kern .3pt t)$, $y(0) = 1$, $y'(0) = 0$.
% {\em (a)} If $\nu$ is set equal to the resonant frequency $\omega $
% for this equation, compute the time $t_c^{}$ at which $y(t)$ first
% reaches the value $10$.
% {\em (\kern .7pt b)} What
% is the smallest value of\/ $\nu$ for which $y(t)$ reaches the value 
% $10$ at some time $t\in [\kern .3pt 0,100\kern .3pt]\kern .5pt ?$
% \par
% {\em Exercise $8.2$.  RLC circuits and AM radio.}
% An AM radio station broadcasts radio waves consisting of a high
% frequency carrier (say, $10^6\kern -1.5pt$ Hz) times a low-frequency oscillation
% (a few thousand Hz).  This is equivalent to saying the signal is contained
% in a band of a few thousand hertz about $10^6\kern -1.5pt$ Hz.  The radio
% is tuned by means of a resonant circuit that
% selects energy in this band.  The simplest such circuit consists of
% a resistor of resistance~$R$ (in ohms), an inductor of
% inductance $L$ (in henries), and a capacitor of capacitance~$C$
% (in farads) in series.
% If $E(t)$ is the applied voltage (in volts) and
% $I(t)$ is the current (in amps) as functions of time,
% then $I$ satisfies the ODE $LI'' + R\kern .4pt I'
% + C^{-1} \kern -.8pt I = E\kern .5pt{}'$.
% {\em (a)} Show that the natural frequency of oscillation (corresponding
% to $R$ small enough to be negligible) is $(LC\kern .5pt )^{-1/2}$.
% If $L =
% 1 \hbox{ henry}$, what value of $C$ is needed to tune in a station
% at 680 KHz?
% {\em (\kern .7pt b)} Suppose it is desired to make the half-width of the resonance
% $1000$ Hz in the sense that signals at $679$ or $681$ KHz generate
% responses of half the amplitude of a signal at $680$ KHz.  What's the
% right choice of $R\kern .7pt$?  Is this subcritical, critical, or supercritical
% damping?
% \par
% {\em \underline{Exercise $8.3$}.  1D analogue of Chladni patterns.}
% {\em (a)} Plot
% the solution of $y'' + 1000\kern .3pt y = e^x$, $y(0) = y(\pi) = 0$.
% Why does it have such a regular shape, and why is the number of
% maxima what it is?  Why does the shape become even more regular if
% 1000 is changed to 1020\kern .3pt?
% {\em (\kern .7pt b)} Answer the same questions for 
% $y'''' - 10^6y = e^x$, $y(0) =y''(0) = 0$,
% $y(\pi) = y''(\pi) = 0$, with $10^6$ then changing to $1.05\times 10^6$.
% \par
% {\em Exercise $8.4$.  High tides in coastal cities.}
% {\em (a)} Find out the date of the next full or new moon in Honolulu, 
% Lisbon, Sydney, and a fourth coastal city of your choosing.
% {\em (\kern .7pt b)} Find out the times of the two high tides in these cities
% on this date.  For cities observing daylight saving time, be sure to correct
% appropriately so as to get high tides in standard local time.
% {\em (c)} Figure 8.12 suggests the high tides should be at
% approximately 6am and 6pm, whereas if the tidal bulges were aligned with
% the moon, it would be noon and midnight.  Which of these scenarios
% do your data come closer to?  How close?\footnote{In the final weeks
% of writing this book, author LNT visited the Holy Island of Lindisfarne
% just before the solar eclipse of August 21, 2017.  When
% there is a solar eclipse, there must be a new moon syzygy,
% so Fig.~8.12 suggests high tides at 6am and 6pm.  Tides matter a great
% deal on Lindisfarne, because the causeway is underwater for ten
% hours each day!  The actual high tide in the afternoon of
% August 21 was at 14:24, alas --- not such a good match with the figure.}
% \par
% {\em \underline{Exercise $8.5$}.  Random forcing.}
% Repeat Figure 8.7 but with the forcing function replaced
% by \verb|f = randnfun([0,200])|, a smooth random function containing
% a wide range of wave numbers (see Chapter 12).  Run the code
% three times so as to see responses to three random functions, and
% discuss the shape and size of the outputs.
% \par
% {\em Exercise $8.6$. Beating.}
% Figures 8.2 and 8.10 show beating effects that
% arise when two waves of nearby frequencies are added.  
% {\em (a)} Use trigonometric identities to derive the formula
% $\cos(\omega t) + \cos((\omega + 2\kern .5pt\varepsilon) t) = 
% 2\cos((\omega + \varepsilon)\kern .5pt t)\cos(\varepsilon \kern .3pt t)$ for 
% arbitrary constants $\omega$ and $\varepsilon$.
% {\em (\kern .7pt b)}  Relate this formula to one of these
% figures, and discuss what adaptation
% would be needed to relate it to the other.
% \par
% {\em \underline{Exercise $8.7$}. Damping and phase lag.}
% Let $\omega=1$ and $\varepsilon = 0.05$ and define a chebfun $f$
% for the denominator of (8.9) over the range $0.5\le \nu \le 1.5$.
% Plot {\tt angle(1/f)}.  Repeat for $\varepsilon = 0.005$ and
% relate the plots to the discussion about phase lag as a function of
% $\kern .8pt\nu$.
% </latex>

