Mathematics 132 – Calculus for Physical and Life Sciences 2 Lab Day 2: direction fields for Differential Equations and Euler’s Method March 14, 2008

Background

To study first order differential equations

y′ = f(t, y)

and their solutions qualitatively, we can use the graphical direction field associated to the equation. Recall, the direction field is a picture obtained by placing at each point (t_{0}, y_{0}) in the plane a small line segment of slope equal to the number f(t_{0}, y_{0}). As we will see, Maple draws these as arrows. A solution of the differential equation is then a function y = g(t) whose graph has slope equal to f(t, g(t)) at each point (t, g(t)) on the graph. That is, the graph “follows the direction field” so that at each point, its tangent line has the same slope as the direction field arrow at that point.

Today, we will draw some additional direction fields, use them to visualize solutions, and see how Euler’s Method applies to give approximate solutions.

1. Direction Fields in Maple

Begin by entering

                              with(DEtools);
                               with(plots);

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 direction field for an equation

y′ = f(t, y)

you can enter a command of the following format:

            DEplot(diff(y(t),t)=f(t,y(t)),y(t),t=a..b,y=c..d);

where:

• the f is the expression for the slope function f(t, 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(t) everywhere. For example, to plot the direction field for the equation \frac{dy}{dt} = \frac{7t−y}{t+2y}, you can enter a command like

    DEplot(diff(y(t),t) = (7*t-y(t))/(t+2*y(t)),y(t),t=-2..2,y=-2..2);

• the ranges of t- and y-values indicate the portion of the plane that will be plotted with the direction 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 direction field on the given region of the plane. By eye, analyze the behavior of the solution passing through the given points (t_{0}, y_{0}) – that is the solution of the differential equation and the initial condition y(t_{0}) = y_{0}. What do think the graph does as t → +∞?

A)

Differential equation: y′ = −4ty, Region: −3 ≤ t ≤ 3, 0 ≤ y ≤ 10, Initial point: (0, 8)

B) Differential equation: y′ = y(y − 1)(y − 2), Region: −3 ≤ t ≤ 3, −1 ≤ y ≤ 3, Initial points: (0, 0), (0, 0.5), (0, 1.5), (0, 2.01).

C) Differential equation: y′ = exp(−t^{2} + y), Region: −3 ≤ t ≤ 3, −10 ≤ y ≤ 10, Initial point: (−3, −1).

Lab Questions, Part II

In this part of the lab, you will use Maple to carry out the calculations for Euler’s Method on the equation from Lab Question I A and plot the results similarly to what we did in the example from class yesterday.

A) The following Maple commands will generate a table of approximate values of the solution of y′ = −4ty with y(0) = 8 on [0, 1] with n = 4, so Δt = .25.

 tl[0]:=0:  yl[0]:=8:
 for i to 4 do
    tl[i]:=tl[i-1]+.25;
    yl[i]:= yl[i-1]-4*tl[i-1]*yl[i-1]*(.25);
 end do;

(To enter these, type Shift/Enter at the end of each line to start a new line, but staying within the same execution group.) Then the following commands will plot the direction field, the piecewise linear approximate solution graph made by connecting the dots for the points computed above

DirField:=DEplot(diff(y(t),t)=-4*t*y(t),[y(t)],t=-.1..1,y=0..10):
Pts:=plot([seq([tl[i],yl[i]],i=0..4)],style=point,symbol=circle,color=blue):
Lines:=plot([seq([tl[i],yl[i]],i=0..4)],color=black):

   display(DirField,Pts,Lines);

Enter these and execute them to see the graph. B) Now, modify the lines above computing the t- and y-lists to compute a similar table

of values but with n = 20, not n = 4. There are number of things you will need to change – be sure you find them all!

C) If you look carefully at your plots from parts A and B here, you should see that there are times when Euler is underestimating the value you would get by following the direction field exactly and other times when Euler overestimates. What is the pattern? What property of the actual solution says that Euler underestimates? What property of the actual solution says that Euler overestimates?

Plotting Solutions in Maple

To plot solutions of a differential equation, together with the direction field, we can use the same DEplot command above, but with different options. For example, to plot the solution of the equation y′ = −4ty with y(0) = 8, for 0 ≤ t ≤ 1, you would enter a command like

 DEplot(diff(y(t),t) = -4*t*y(t),y(t),t=0..1,[[y(0)=8]],linecolor=black);

If you want to see several solution curves, you can place a list of initial conditions, separated by commas, in the [] brackets after the t = 0..1. For instance to see solution curves with y(0) = .5 and y = 1 on the same axes, change to [[y(0) = .5], [y(0) = 1]]. Note: The default color for the solution curve is a shade of gold that does not show up 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(t))

• then the range of t-values for which you want to see the graph of the solution.

• 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 III

D) For each of the differential equations in questions I A,B,C above, generate a single plot showing the direction field and the solution(s) starting at the given point(s). Did those solutions look like what you expected?

E) For equation C, experiment with different initial conditions y(−3) = y_{0}. What is the “cut-off” value for y_{0} between solutions that tend to a finite value as t → ∞ and those that grow without any bound?

NOTE: In all questions here, some care may be needed to get reasonable graphs. As you will see, some of these solutions grow extremely fast and you may get nonsense output or an error message when that happens. One possible solution is to put in a range of y-values after the initial conditions in the DEplot command if you suspect that there’s a problem.

The graphing terminates when the solution curve leaves the window you defined. Try a restriction like y = -10..10. Assignment

Writeups due in class on Friday, March 28.