Mathematics 134 – Intensive Calculus for Science 2 Lab Day 4: Slope Fields for Differential Equations April 4, 2006

Background

To study first order differential equations

\frac{dy}{dx} = F (x, y)

and their solutions, we can use the graphical 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 using arrows rather than plain line segments. 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 “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.

1. Slope Fields in Maple

To plot slope fields for differential equations in Maple, you need to begin by entering

                              with(DEtools);

once at the start of the session. Note the capitalization, which is necessary; DE stands for Differential Equation, 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 DEplot command available – the main operation 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

\frac{dy}{dx} = F (x, y)

you can enter a command of the following format:

            DEplot(diff(y(x),x)=F(x,y(x)),y(x),x=a..b,y=c..d);

where:

• the F is the expression for the slope function F (x, y). You enter that in usual Maple format (or use a symbolic name for the expression).

• The dependent variable (unknown function) in the differential equation should be entered in the form y(x) everywhere. For example, to plot the slope field for the equation \frac{dy}{dx} = 4xy, you can enter a command like

          DEplot(diff(y(x),x) = 4*x*y(x),[y(x)],x=-2..2,y=-2..2);

• the ranges of x- and y-values indicate the portion of the plane that will be plotted with the slope field. A standard number of grid points is used.

Lab Questions, Part I

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 points (0, y_{0}) – that is the solution of the differential equation and the initial condition y(0) = y_{0}. Describe in words what you think the solution does for the given range of x-values.

A) Differential equation: \frac{dy}{dx} = 4x − y − 4, Region: 0 ≤ x ≤ 2, −2 ≤ y ≤ 2, Initial point: (0, 1)

B) Differential equation: \frac{dy}{dx} = (y^{2} − 8y + 12)/5, Region: 0 ≤ x ≤ 10, 0 ≤ y ≤ 10, Initial points: (0, 1), (0, 2.3), (0, 7).

C) Differential equation: \frac{dy}{dx} = sin(x) cos(y/2), Region: 0 ≤ x ≤ 2π, −π ≤ y ≤ π, Initial point: (0, −2).

Plotting Solutions in Maple

To plot solutions of a differential equation, together with the slope field, we can use the same DEplot command above, but with different options. For example, to plot the solution of the equation \frac{dy}{dx} = 4xy with y(0) = .5, for 0 ≤ x ≤ 1, you would enter a command like

DEplot(diff(y(x),x) = 4*x*y(x),[y(x)],x=0..1,[[y(0)=.5]],linecolor=black);

Note: The default color for the solution curve is a kind of gold that does not show up well when you print a worksheet on a black and white printer. Hence we use the option linecolor=black. The general format is:

• the differential equation will always come first,

• then the dependent variable or unknown function ([y(x)])

• then the range of x-values for which you want to see the graph of the solution. 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!

• then, in square brackets, separated by commas, a list of initial conditions [y(a)=b]. In the example above, there’s just one, but any number can be included.

Lab Questions, Part II 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?

Assignment Writeups due in class on Friday, April 7.