\magnification=\magstep1
\centerline{Mathematics 304, section 2 -- Ordinary Differential Equations}
\centerline{Lab Day 1 -- Maple for Differential Equations, Bifurcations, etc.}
\centerline{September 20, 2004}
\bigskip
\noindent
{\it Background}
\bigskip
Today, we want see how to use Maple to plot direction
fields and approximate solutions for first order ODE.
We will also look at further examples of bifurcations 
in the family of equations
$$x' = ax - x^3 - b$$
where $a,b$ are two independent real parameters.
\bigskip
\noindent
{\it Maple Commands for Plotting Functions, Direction Fields and Solutions}
\bigskip
\noindent
The Maple commands that we will use today are:
\bigskip
\item{} {\tt plot} to plot ordinary functions of one variable
\item{} {\tt animate} to see animated 2D plots
\item{} {\tt DEplot} to plot direction fields and solutions of an ODE
\bigskip
\noindent
The basic Maple command for 2D plotting 
graphs of the form $y = f(x)$ is called {\tt plot}. The basic format is 
\medskip
\centerline{\tt plot(function,range,options);}
\medskip
\noindent
where: {\tt function} is the function to be plotted -- the simplest way to
specify one is via a formula, {\tt range}
is the range of x-values you want to see plotted, and
{\tt options} can be used to control the form of the plot if desired.
No options need be specified, however, so that part can
be absent.  For example 
\medskip
\centerline{\tt plot(x\^{}4-x\^{}3+2*x-5*sin(x\^{}2),x=1..3,title="My First Maple Graph");}
\medskip
\noindent
will plot 
$$y = x^4-x^3+2x-5\sin(x^2)$$
on the range $1 \le x \le 3$, and add a title.

An example of the {\tt animate} command is given in the Lab Questions 
below.

The {\tt DEplot} command is part of the {\tt DEtools} package; to use it you will need
to start by entering the command:
\medskip
\centerline{\tt with(DEtools):}
\medskip
\noindent
to load the {\tt DEtools} routines.  Note: the colon at the end
of a Maple command {\it suppresses the output} -- the command is 
executed but the results are not displayed.  In this case the output 
would be a  (long) list of the commands that are parts of the package -- 
maybe interesting, but wasteful of paper when you go to print out your 
worksheet!
\vfill\eject
\noindent
{\it A Worked Example}
\bigskip
For instance, suppose we wanted to study the direction field, 
and solutions of various initial value problems for the 1st order
ODE $y' = ty - 1$.  Specifically, say we wanted to plot 
the solution of the initial value problem with $y(0) = 1$ for $t \in [-1,1]$
(this is chosen arbitrarily here).  We could use the following commands.
First we define the slope function $f(t,y) = ty - 1$:
\medskip
\centerline{\tt f := (t,y) -> t*y - 1;}
\medskip
\noindent
Then we set up the differential equation in Maple's format:
\medskip
\centerline{\tt eq := diff(y(t),t) = f(t,y(t));}
\medskip
\noindent
Then we use {\tt DEplot} to generate the plot we want:
\medskip
\centerline{\tt DEplot(eq,y(t),t=-1..1,[[y(0)=1]],linecolor=black);}
\medskip
\noindent
When you execute the {\tt DEplot} command the output will be a plot
showing the direction field (with line segments drawn as arrows pointing
in the direction of increasing $x$), together with a plot of the solution.

\bigskip
\noindent
{\it Comments:}
\bigskip
\item{1.}  The 3-step process above could actually be combined into
a single command if you put the definition of the differential equation
directly into the {\tt DEplot} command (instead of building it up 
using the slope function).  I recommend that you do things this
way though, at least at first, to keep everything straight in your 
mind and minimize the chance for typing errors. 
\item{2.}  The general format of the {\tt DEplot} command is 
\medskip
\centerline{\tt DEplot(equation,depvar(indepvar),range,inits,options);}
\medskip
\item{} where {\tt equation} is the differential equation, in the format
given above.  After the equation comes the name of the dependent variable
(i.e. the unknown function) with the independent variable in parentheses,
then the range of values of the independent variable you want to see plotted,
then the initial conditions, and options last.  {\it The order of these
is fixed -- you cannot mix them up freely.}  You can plot several different
solutions together by putting more than one initial condition inside
the outer pair of square brackets, separated by commas, e.g.
{\tt [[y(0) = 1],[y(0)=2],[y(-1)=2]]}.  Options can be used to control
the way solutions are plotted and the appearance of the plot.  The {\tt 
linecolor=black} in the above is an option, for instance.  Without that,
Maple would use a default yellow color that does not show up when 
you print your worksheet(!)
\item{3.}  To draw the solution, Maple is using an {\it approximate numerical
method} similar to, but more powerful than, the {\it Euler's Method} you 
may have studied in calculus.  Methods of this type produce a table of 
values for an approximate solution function by ``following the direction 
field''.  Then Maple plots the 
approximate solution by connecting the points with straight line segments.
{\it This method is far from fool-proof!}  In particular, if the slope
function is changing rapidly, discontinuous at some points, etc., it can lead 
to inaccurate results.  Fortunately, there are ways to try to fine-tune
its behavior.  If you notice that your approximate solution looks
very jagged (adjacent straight line segments have very different slopes)
or if it jumps around wildly, you can try including an option
\medskip
\centerline{\tt stepsize=.01}
\medskip
\item{}
or some number even smaller than $.01$.  The step size is the spacing between
successive values of the independent variable when Maple computes the 
approximate solution.  Reducing the stepsize from its default value can
improve plots.  {\it It also slows down the computation, though, because
more points must be computed!}  If the slope function is discontinous
at some point on your solution, this may not help; in some cases, this
type of method will always fail no matter how small the step size is!
\item{4.}{\it IMPORTANT NOTE:}  Some initial conditions with some differential
equations lead to solutions that become unbounded extremely quickly.  
If this happens Maple will probably ``punt'' on trying to draw them
and return a blank graph with a message that says:
{\it Floating Point Overflow.  Please shorten axes.}
This means that you need to {\it reduce the range of values of the
independent variable}.
\bigskip
\noindent
{\it Lab Questions}
\bigskip
All parts of questions A-E in this lab refer to the family of
first order ODE's 
$$x' = ax - x^3 - b.\leqno(1)$$
The goal here is to understand the bifurcations that 
occur in this family, and to generate a sort of ``2D bifurcation
diagram'' illustrating the possibilities.  Some of the parts of these
questions ask you to generate hand sketches of phase lines,
bifurcation diagrams, and so forth.  You can do those on separate
sheets and attach them to your Maple printout.
\bigskip
\noindent
A)  Set $a = 1$ in the general form (1)
\medskip
\item{1)}  With $b = -2$, then $b = 0$, then $b = 2$
use the {\tt DEplot} command
described above to plot approximate solutions of this equation with 
initial conditions $x(0) = -2,-1/2,1/2,2$ (all on the same axes).
Sketch the phase line for this equation with $a = 1$ and 
each of these  $b$-values
(by hand) and explain how they relate to your solution graphs.
\item{2)}  Plot $y = x - x^3 - b$
(ordinary function plot) for various $b$. For another way to see this,
you may find it helpful to use animation:
\medskip
\centerline{\tt with(plots):}
\centerline{\tt animate(x-x\^{}3-b,x=-2..2,b=-2..2);}
\medskip
\item{}
The toolbar buttons that show up when you left click over the plot
region act like the controls on a cassette tape player (rememeber those??)
Use them to ``play the animation''.
(Note: the default gives 16 ``frames'' in the animation -- 
16 equally spaced $b$-values starting at $b=-2$, increasing to
$b = +2$.) 
Using the information from these plots, sketch
the bifurcation diagram for the family $x' = x - x^3 - b$ as $b$ varies
(you'll want to do this by hand).
\bigskip
\noindent
B)  Sketch the bifurcation diagram for the family with $a = 0$ and 
$b$ varying.  You may want to repeat calculations as in question A
to see the pattern.  Include any Maple plots you generate in your
lab write-up.
\bigskip
\noindent
C)   Sketch the bifurcation diagram for the family with $a = -1$,
and $b$ varying.  Include any Maple plots you generate in your
lab write-up.
\bigskip
\noindent
D)  Now consider the families with $b = -1, 0, 1$ and $a$
varying.  Sketch the bifurcation diagram for each of these families.
Include any Maple plots you generate in your
lab write-up.
\bigskip
\noindent
E)  (``Putting it all together'')  
The goal now is to construct a 
plot of the $a,b$-plane showing the regions where $x' = ax - x^3 - b$
has different numbers of equilibrium points.  
\medskip
\item{1)}  Show in general that if $f(x)$ is a polynomial of 
any degree and $f(x)$ has a multiple root (i.e. double or higher
multiplicity) at $x = c$, then 
$$f(c) = f'(c) = 0.$$
\item{2)}  Show that for a cubic of the form $f(x) = ax - x^3 - b$,
there exists some $c$ with $f(c) = f'(c) = 0$ if and only if 
$$4a^3-27b^2 = 0.$$
The expression $4a^3-27b^2$ is called the {\it discriminant}
of the cubic -- it's a generalization of the $b^2 - 4ac$ under
the radical sign in the quadratic formula for the roots
of $ax^2 + bx + c = 0$(!)  If you take our
Abstract Algebra course (MATH 351-352), you may see discriminants
of polynomials again in more generality. 
\item{3)}  What are the different numbers of 
equlilibrium points in the family?  Which regions in the $(a,b)$-plane
correspond to ODE's $x' = ax - x^3 - b$ with each possible number?
\item{4)}  Describe using phase lines and the graph $y =   ax - x^3 - b$
the bifurcations that occur when you cross from one region into another.
Is there a difference depending on whether the cross-over happens
at $(0,0)$ or a point different from $(0,0)$?
\bigskip
\noindent
F)  Let's add on a periodic term like in our discussion of periodic
harvesting in class.  Consider the differential equation
$$x' = x - x^3 - (0.1)\sin(2\pi t)$$
Study the solutions and determine whether there appear to be 
any periodic solutions.
\bigskip
\noindent
{\it Assignment}
\bigskip
Lab writeups due Friday, September 24.  (This is the same day as the due date
for Problem Set 3; the problem set is very short this time for this reason.)
\bye

