       Re: Plotting The Slope field of a differential equation

• To: mathgroup at smc.vnet.net
• Subject: [mg36484] Re: [mg36430] Plotting The Slope field of a differential equation
• From: Murray Eisenberg <murraye at attbi.com>
• Date: Sun, 8 Sep 2002 03:31:34 -0400 (EDT)
• Organization: Mathematics & Statistics, Univ. of Mass./Amherst
• Sender: owner-wri-mathgroup at wolfram.com

```This is a question that's been asked and answered a number of times. One
answer, by me, can be found by going to www.wolfram.com and selecting
first Resource Library and then MathGroup on the Resource Library page;
then search for "direction field".  You'll find, among many others, the URL:

http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00163.html

(This is not to chastise you for not first looking there, but to suggest
a way for you to find answers more efficiently than waiting for the
post-message/wait-for-response involved in writing to this mailing list.)

Here again is what I wrote (for a different ODE, y' = 1/y):

ou need to load the package, then manufacture a vector field whose plot
is the "slope field" (what you call "vector flow diagram").  To do the
latter, let me separately define the function giving the right-hand side
of the ODE; you don't really have to do that, but could instead directly
use as the first argument to PlotVectorField the right-hand side of my
definition of f.

<< Graphics`PlotField`

f[t_, y_] := {1, 1/y}

field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3}];

I gave a name to the graphics result just in order to re-display the
field below along with the graph of one solution.  First, find a general
solution:

soln = First @ DSolve[{y'[t] == 1/y[t], y == 1}, y[t], t]
{y[t] -> Sqrt*Sqrt[1/2 + t]}

grf = Plot[y[t] /. soln, {t, 0, 3}];

Now combine the plot with the field:

Show[grf, field];

Note that PlotVectorField does not always give quite the result you
might want, since the vector lengths are scaled with respect to the
magnitude of the actual vectors.  You might want just a "direction
field" in which all arrows have the same length.  You can produce such a
graphic by using the ScaleFunction and ScaleFactor options to
PlotVectorField.  For example:

field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3},
ScaleFunction -> (1 &), ScaleFactor -> 0.175];

John M. Resler wrote:
Hello once again,
... I have several differential equations I would like to
plot in Mathematica. I would like to plot the Slope Fields of them
though. Can anyone lead me in the right direction? I can solve the
equations trivially but I want to display the slope fields. An example
follows :

y' + 2y = 3
...

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street
Amherst, MA 01375

```

• Prev by Date: Re: Re: word processing with mathematica
• Next by Date: RE: Re: fourier transform time
• Previous by thread: Re: Plotting The Slope field of a differential equation
• Next by thread: Plot several graphs generated by Table