Skip to main content

Exploring Calculus with Maple Introductory Calculus

Section 16.3 Direction Fields

A direction field is a way to visualise the family of functions that make up the general solution to a first-order differential equation. At every point on the graph, a short arrow is draw that represents the slope of the tangent line to a solution curve passing through that point. This can be quite useful to get a visual interpretation of how solutions to a differential equation behave.
We use the DEplot() to plot the direction field for a differential equation and it requires that the DETools package is loaded first. Packages are loaded using the with() command and it is typically a good idea to load any necessary packages at the top of your worksheet. Loading a package only needs to be done once per Maple worksheet, but needs to be run each time you open a new or previously closed document.
As an example, we will take a look at the direction field for the differential equation
\begin{equation*} y'=x^2\sin(y)\text{.} \end{equation*}
It is best to assign a name to this equation so that we can use the DEplot() command multiple times conveniently.
> de2 := y'(x) = x^2 * sin(y(x));
\begin{equation*} \displaystyle de\mathit{2}\, := \,{\frac {d}{dx}}y \left( x \right) ={x}^{2}\sin \left( y \left( x \right) \right) \end{equation*}
The required parameters for the DEplot() command are the differential equation, the function for which it is to be solved for, and the ranges of the two variables.
> with(DETools):
> DEplot(de2, y(x), x=-2..2, y=-2..2);
The above direction field allows us to track a β€œsolution curve” for any particular initial condition. To track this curve, we start at a point \((x_0, y_0)\) and follow the directions of the arrows. This will give us the one unique curve that satisfies the initial condition \(y(x_0)=y_0\text{.}\)
Maple will plot a particular solution if the initial condition is placed inside square brackets and included as an additional parameter in the DEplot() command.
Suppose we wish to add the initial condition \(y(0)=1\) and view the particular solution on the direction field.
> DEplot(de2, y(x), x=-2..2, y=-2..2, [y(0) = 1]);
Notice that this curve goes through the point \((0,1)\) and follows the direction of the arrows from the direction field.
Multiple particular solutions can be plotted at once. Here we plot the solutions that correspond to the initial conditions \(y(0)=1\) and \(y(2)=-1\text{:}\)

Aside

> DEplot(de2, y(x), x=-2..2, y=-2..2, [y(0) = 1, y(2) = -1], 
  linecolour=[blue, cyan]);