next up previous
Next: Lower level routines: DEplot1 Up: Plotting direction fields and Previous: Direction fields only: fieldplot

Higher level DEtools routines: dfieldplot and phaseportrait

The syntax for these two commands is very similar, so we describe them together. The dfieldplot routine plots direction fields for a single first order differential equation or a two-dimensional system of (autonomous) differential equations. That is, it does essentially the same thing as fieldplot. The syntax is slightly more complicated than for fieldplot, but dfieldplot has the advantage that it produces better arrows and direction fields that are easier to interpret.

The DEtools package only appeared with Release 3 of Maple. Before that, it was very difficult to plot solution trajectories for nonlinear differential equations. While I'm not exactly thrilled with the DEtools package, it was a big improvement on what was available in Release 2.

An example of using dfieldplot with a single first order equation appears below. Note that the first command loads the DEtools package. It is only necessary to do this once in each session.

  > with(DEtools);


  > de1 := sin(x^2);


  > dfieldplot(de1,[t,x],t=0..5,x=-2..2);

The first argument to dfieldplot is always the differential equation (or system of differential equations, as we'll see below). The second argument lists the independent variable t and the dependent variable x. This argument must be present, and t must appear first. The third argument specifies a range for the independent variable, and must be present. The fourth argument, specifying a range for the dependent variable, is optional but usually needed so that the command plots the x range you are interested in. There are several other optional arguments, see the help page for more details.

Note that we used vector field notation to specify the differential equation. That is, all we did was specify the function f(x,t) from the right-hand side of equation 1. The help page implies that you can also use a differential equation as the first argument,as in the following example.

  > dfieldplot(diff(x(t),t)=sin(x(t)^2),[t,x],t=0..5,x=-2..2);

However, this has the following consequences.

  1. On a DEC Alpha machine, this command crashes the session immediately.
  2. On other platforms I have tried, it doesn't crash Maple, but it slows the command down tremendously.
My recommendation is to always use the vector field notation.

Next, we present an example of dfieldplot usage for a two-dimensional autonomous system. The main difference from our first example is that two differential equations must be specified. Again, vector field notation should be used.

  > sys1 := [y,-4*x];


  > dfieldplot(sys1,[x,y],t=0..1,x=-2..2,y=-2..2);

As in our previous example, only the first three arguments are required. However, I can't really think of a reason for not specifying ranges for x and y.

There are several optional arguments to dfieldplot. One of the most useful is the arrows option, which can be used to change the appearance of the arrows. Here is one example.

  > dfieldplot(sys1,[x,y],0..1,x=-2..2,y=-2..2,arrows=SLIM);

Other possible values for the arrows option are THICK (big arrows), LINE (no arrowheads), SLIM (like thin, but with better arrowheads), and NONE (no direction field - don't use this option with dfieldplot).

The phaseportrait command is even more useful. What it does, essentially, is to plot solution trajectories for a set of initial conditions that you specify. Optionally, phaseportrait can plot the trajectories and the direction field. Here is an example of using phaseportrait to plot two trajectories for our two dimensional system, equation 4.

  > phaseportrait(sys1,[x,y],t=0..1,[0,0,1],[0,1,0],x=-2..2,y=-2..2);

The first four arguments to phaseportrait are required. First comes the system of differential equations. The second argument is the list of dependent variables. The third argument specifies a range for t. In the example, we specified the range t=0 to t=1, but you might have to use a larger or smaller range. The fourth argument is a set of lists. Each list in the set represents an initial condition, giving the values of t, x and y. For example the list [0,0,1] represents the initial condition x(0) = 0 and y(0)=1. The first item in the list is the value of t. More initial conditions could have been specified by including more lists in the set.

The phaseportrait command can also plot direction fields if you specify the arrows option. Here is an example.

  > phaseportrait(sys1,[x,y],t=0..1,[0,0,1],[0,1,0],[0,1/2,-1/2],

The arrows argument can only have the values given above for the dfieldplot command. The value NONE is the default if you don't use this optional argument.

In the previous examples we have used a relatively short time interval. Many times you need to use a longer time interval. This can result in a very jagged plot, like from the following command.

  > phaseportrait(sys1,[x,y],t=0..5,[0,0,1],[0,1,0],x=-2..2,y=-2..2);

The reason for the jagged appearance is that the numerical integration is being done with a stepsize that is too large. The fix is to set the step size with the stepsize command as in the following command.

  > phaseportrait(sys1,[x,y],t=0..5,[0,0,1],[0,1,0],x=-2..2,y=-2..2,stepsize=0.1);

If the plot is still jagged after you decrease the step size, try decreasing it again. However, the smaller the step size, the longer the integration takes, so be cautious in reducing the step size.

Using the phaseportrait command to plot trajectories for a single first order differential equation is straightforward. See the following example.

  > phaseportrait(de1,[t,x],t=0..2,[0,1],[0,2]);

Note that only two values have to be specified for each initial condition. The arrows option can be used to plot the direction field along with the trajectories.

Finally, the phaseportrait command can be used to plot individual components versus t by using the scene optional argument. Here is an example of plotting x versus t for our two-dimensional system.

  > phaseportrait(sys1,[x,y],t=0..1,[0,0,1],[0,1,0],scene=[t,x]);

You might wonder why you would want to do this. One common reason to plot a single component is to determine the approximate period when a solution is periodic.

next up previous
Next: Lower level routines: DEplot1 Up: Plotting direction fields and Previous: Direction fields only: fieldplot

William W. Farr
Thu Oct 24 13:33:53 EDT 1996