**Slope Fields and Exact Solutions in Maple**

**Copyright © 1999, 2002 by James F. Hurley, University of Connecticut Department of Mathematics, 196 Auditorium Road, Unit 3009, Storrs CT 06269-3009. All rights reserved.**

**1. Slope Fields.**
Maple has a collection of useful routines in its DEtools library. A very handy one plots the direction field of simple equation
*dx/dt *
=
*f(x, t). *
The simple routine below illustrates use of the command
dfieldplot
to generate a plot of a slope field. The syntax of this command is

dfieldplot(deqn, depvar(indvar), indvar = a..b, depvar = c..d)

where

¥
deqn
is the differential equation that you define prior to calling
dfieldplot

¥
depvar
is the dependent variable (that is, in the notation
*dx/dt *
=
*f(x, t)*
above, the variable
*x*
)

¥
indvar
is the independent variable (that is, in the current notation, the variable
*t*
)

¥ the direction field plots for the range
*a*
to
*b*
of
indvar
and
*c*
to
*d*
of
depvar
.

Execute the routine by placing the cursor at the end of each block of code in turn, and hitting the Enter key. The first command simply prints out the differential equation whose direction field will be plotted. Compare the output from the second command with Figure 2.7.1 of Florin Diacu's text,
*Introduction to Differential Equations*
/
*Order and Chaos*
(Freeman, 2000), p. 72.
Notice that you need to load the
plots
package in order to use the
display
command.

`> `
**with(plots):
with(DEtools) :
**

`> `
**with(plots):
with(DEtools) :
slopes := dfieldplot(de, x(t), t = -1..9, x = -5..5) :
display ( slopes);**

Notice that the field seems to have some odd characteristics in certain areas.

Unlike the package Differential Systems, Maple does not include a built-in provision for generating a solution with a given initial value just by clicking on the point. (It is possible to create a Maple routine for that, but the availability of Differential Systems lessens the motivation to do so.) However, it is not difficult to have Maple graph initial-value solutions. The built-in command
dsolve
operates somewhat like Differential Systems: it generates an analytic (or numerical) solution starting from the initial-value point. You can then ask Maple to plot that solution. The following routine illustrates how to plot several solutions of the above equation from Section 2.7 of
*Diacu*
:

=

`> `
**with (plots):
with (DEtools):
soln := dsolve ( {de, x(0) = c}, x(t) ):
x_1 := subs ( c = 1, rhs(soln) ) :
x_2 := subs ( c = 0, rhs(soln) ) :
x_3 := subs ( c = -1, rhs(soln) ) :
x_4 := subs ( c = -2, rhs(soln) ) :
x_5 := subs ( c = 2, rhs(soln) ) :
x_6 := subs ( c = 3, rhs(soln) ) :
x_7 := subs ( c = -.9, rhs(soln) ) :
solns := plot( {x_1, x_2, x_3, x_4, x_5, x_6, x_7}, t = -1..9, x = -5..5, color = blue) :
display(solns);
**

Finally, the next routine combines the two plots into one that displays the solutions and the slope field together. Note the continuing display odd features: for example, the apparent asymptote near
*x*
=
*e*
and the absence of a solution symmetric to the one in the first quadrant to which others appear to converge.

`> `
**with(plots):
display( slopes, solns);
**

**2. Checking closed-form solutions.**
As the preceding example illustrates, Maple's
dsolve
command finds a closed-form solution for a first-order initial-value problemÑsuch as first-order linearÑfor which a standard technique can generate a formula for the unique solution. In discussing Euler's method, recall that we dealt with the first-order linear initial-value problem

=
, where
*x*
(0) = 1.

Using the methods of Section 2.3, we asserted that this problem has the solution
*x*
(
*t*
) =
. The next Maple routine confirms that assertion:

`> `
**with(DEtools):
dsolve({diff( x(t), t) = 2*t*x(t) + exp(t^2), x(0) = 1}, x(t)) ;**

`> `

Thus, Maple can check your solution to such a problem if you have a discrepancy with another member of your study group, or the answer section of the text.