\magnification = \magstep1
\overfullrule=0pt
\centerline{Mathematics 36, section 5 -- AP Calculus}
\centerline{Lab Day 5:  Slope Fields}
\centerline{November 9, 1999}
\bigskip
\noindent
{\bf Background}
\bigskip
Yesterday we began studying first order differential equations
$${dy \over dx} = f(x,y)$$
and their solutions by means of the graphical {\it slope field\/} associated
to the equation.  Recall, the slope field is a picture obtained
by placing at each point $(x_0,y_0)$ in the plane a small line segment
of slope equal to the number $f(x_0,y_0)$.  As we will see, 
Maple draws these as {\it arrows\/}.  A solution of the 
differential equation is then a function $y(x)$ whose graph has
slope equal to $f(x,y(x))$ at each point $(x,y(x))$ on the graph.  That is,
the graph {\it ``threads its way through the slope field'' so that at each
point, its tangent line is in the direction of the slope field 
arrow at that point\/}.

Today, we will draw some additional slope fields, and use them to visualize
solutions.  
\bigskip
\noindent
{\it 1. Slope Fields in Maple}
\bigskip
To plot slope fields
for differential equations in Maple, you need to begin by entering
\medskip
\centerline{\tt with(DEtools);}
\medskip
\noindent
once at the start of the session.
Note the capitalization, which is necessary; DE stands for 
{\it D}ifferential {\it E}quation, as you might guess.  
This command loads an external package of additional Maple commands for
working with differential equations.  You need to do that to make the 
{\tt dfieldplot} and {\tt phaseportrait} commands available -- the main 
operations we will be using today. The output will be a list of the
commands in the DEtools package.

To plot the slope field for an equation
$${dy \over dx} = f(x,y)$$
you enter a command of the following format:
\medskip
\centerline{\tt dfieldplot(diff(y(x),x)=f(x,y(x)),y(x),x=a..b,y=c..d);}
\medskip
\noindent
where:
\item{$\bullet$} The {\tt f} is the expression for the function $f(x,y)$.  You
enter that in usual 
Maple format (or use a symbolic name for the expression).
\item{$\bullet$}  However, in that function, the dependent variable in the 
differential equation must be entered in the form  {\tt y(x)} everywhere.
For example, to plot the slope field for the equation ${dy\over dx} = 4xy$, you 
would enter a command like
\medskip
\centerline{\tt dfieldplot(diff(y(x),x) = 4*x*y(x),y(x),x=-2..2,y=-2..2);}
\centerline
\item{$\bullet$} the ranges of $x$- and $y$-values indicate the portion of the 
plane that will be {\it plotted\/} with the slope field.  A standard 
number of grid points is used.
(You can also put in options such as a title after the $y$-range if you want.)
\bigskip
\noindent
{\it Lab Questions, Part I}
\bigskip
\noindent
For each of the following of the following differential equations,
generate a plot of the slope field on the given region of the plane.  By eye, analyze the behavior of 
the solution passing through the given point $(0,y_0)$ -- that is the 
solution of the differential equation and the initial condition $y(0) = y_0$. 
Describe the graphs of that solution in words.  For instance,
do those graphs have maximum or minimum points?  Can you tell what the 
graph does as $x \to +\infty$?
\bigskip
\item{A)}  ${dy \over dx} = 4 x - y - 4$, region $0 \le x\le 2, -2 \le y \le 2$,
 point $ = (0,1)$ 
\item{B)}  ${dy \over dx} = (y^2 - 10y + 7)/5$, region $0 \le x \le 10, 0\le y \le 10$, 
point $ = (0,8)$.
\item{C)}  ${dy \over dx} = \sin(x)\cos(y)$,  region $0\le x\le 2\pi, -\pi \le y \le \pi$,
point $ = (0,-1)$.
\bigskip
\noindent
{\it Plotting Solutions in Maple}
\bigskip
To plot solutions of a differential equation, together with the
slope field, another command in the DEtools package, called 
{\tt phaseportrait} can be used.  The format of this command
is similiar to the {\tt dfieldplot} command, except that you also specify the initial
conditions for the solution you want to see.  For example, 
to plot the solution of the equation ${dy\over dx} = 4xy$ with $y(0)=.5$, 
for $0 \le x \le 1$, you 
would enter a command like
\medskip
\centerline{\tt phaseportrait(diff(y(x),x) = 4*x*y(x),y(x),x=0..1,[[y(0)=.5]],linecolor=black);}
\medskip
\noindent
Note: The default color for the solution curve is a gold that does
not show up well when you print a worksheet on a black and white
printer.  Hence we use the option {\tt linecolor=black}.
The general format of {\tt phaseportrait} looks like the example above:
\medskip
\item{$\bullet$}  The differential equation will always come first, entered
as in the {\tt dfieldplot} command.
\item{$\bullet$}  then the dependent variable ({\tt y(x)})  
\item{$\bullet$}  then {\it the range of $x$-values you want to see
the graph of the solution plotted for\/}.  NOTE: some care may be needed
in choosing this range to get reasonable graphs.  If you use too large a
range here, the $y$-coordinates on the solution may cover a 
range too large for reasonable graphing!
\item{$\bullet$}  Then, in square brackets, separated by commas, a list
of initial conditions {\tt [y(a)=b]} (in the example above, there's just one, but
any number can be included).  
\bigskip
\noindent
{\it Lab Questions, Part II}
\bigskip
\noindent
\item{D)}  For each of the differential equations in questions A,B,C above,
generate a single plot showing the slope field and the solutions
starting at the given point.  Did those solutions look like what
you expected?
\item{E)}  Consider the slope field for the differential equation
${dy\over dx} = {y \over 3y^2 - x - 2}$.  {\it Without using Maple\/}, determine
the set of points in the plane 
where the slope field has the value {\it zero}, where it is {\it undefined\/}
(vertical), and the regions of the plane where the slope has positive
and negative signs.  Use that information to give a rough sketch of
the graph of the solution curve with $y(0) = 1/2$.  (You can check 
your work using Maple if you like!)
\bigskip
\noindent
{\bf Assignment:}
\bigskip
Lab writeups due in class, Monday, Nov. 15.
\bye


