2
* Introduction to plotdf::
3
* Definitions for plotdf::
6
@node Introduction to plotdf, Definitions for plotdf, plotdf, plotdf
7
@section Introduction to plotdf
9
The function @code{plotdf} creates a plot of the direction field of a
10
first-order Ordinary Differential Equation (ODE) or a system of two
11
autonomous first-order ODE's.
13
To plot the direction field of a single ODE, the ODE must be written in
23
$${{dy}\over{dx}} = F(x,y)$$
26
and the function @var{F} should be given as the argument for
27
@code{plotdf}. The independent variable is always identified as @var{x},
28
and the dependent variable as @var{y}. Those two variables should not
29
have any values assigned to them.
31
To plot the direction field of a set of two autonomous ODE's, they must
32
be written in the form
36
-- = G(x,y) -- = F(x,y)
41
$${{dx}\over{dt}} = G(x,y) \qquad {{dy}\over{dt}} = F(x,y)$$
44
and the argument for @code{plotdf} should be a list with the two
45
functions @var{F} and @var{G}, in any order.
47
If only one ODE is given, @code{plotdf} will implicitly admit
48
@code{x=t}, and @code{G(x,y)=1}, transforming the non-autonomous
49
equation into a system of two autonomous equations.
51
@node Definitions for plotdf, , Introduction to plotdf, plotdf
52
@section Definitions for plotdf
54
@deffn {Function} plotdf (@var{dydx},...options...)
55
@deffnx {Function} plotdf (@code{[}@var{dxdt},@var{dydt}@code{]},...options...)
57
Displays a direction field in two dimensions @var{x} and @var{y}.
59
@var{dydx}, @var{dxdt} and @var{dydt} are expressions that depend
60
on @var{x} and @var{y}. In addition to those two variables, the
61
expressions can also depend on a set of parameters, with numerical
62
values given with the @code{parameters} option (the option syntax is
63
given below), or with an range of allowed values specified by a
66
Several other options can be given within the command, or entered into
67
the menu that will appear when the upper-left corner of the plot window
68
is clicked. Integral curves can be obtained by clicking on the plot, or
69
with the option @code{trajectory_at}. The direction of the integration
70
can be controlled with the @code{direction} option, which can have values
71
of "forward", "backward" or "both". The number of integration steps is
72
given by @code{nsteps} and the time interval between them is set up with
73
the @code{tstep} option. The Adams Moulton method is used for the
74
integration; it is also possible to switch to an adaptive Runge-Kutta
79
The menu in the plot window has the following options: "Zoom", will
80
change the behavior of the mouse so that it will allow you to zoom in
81
on a region of the plot by clicking with the left button. Each click
82
near a point magnifies the plot, keeping the center at the point where
83
you clicked. Holding the SHIFT key while clicking, zooms out to the
84
previous magnification. To resume computing trajectories when you
85
click on a point, select "Integrate" from the menu.
87
The option "Config" in the menu can be used to change the ODE(s) in use
88
and various other settings. After configuration changes are made, the
89
menu option "Replot" should be selected, to activate the new settings.
90
If a pair of coordinates are entered in the field "Trajectory at" in the
91
"Config" dialog menu, and the "enter" key is pressed, a new integral
92
curve will be shown, in addition to the ones already shown. When
93
"Replot" is selected, only the last integral curve entered will be
96
Holding the right mouse button down while the cursor is moved, can be
97
used to drag the plot sideways or up and down. Additional
98
parameters such as the number of steps, the initial value of @var{t}
99
and the x and y centers and radii, may be set in the Config menu.
101
A copy of the plot can be printed to a Postscript printer, or saved as a
102
postscript file, using the menu option "Save". To switch between
103
printing and saving to a Postscript file, "Print Options" should be
104
selected in the dialog window of "Config". After the settings in the
105
"Save" dialog window are entered, "Save'' must be selected in the first
106
menu, to create the file or print the plot.
110
The @code{plotdf} command may include several commands, each command is
111
a list of two or more items. The first item is the name of the option,
112
and the remainder comprises the value or values assigned to the option.
114
The options which are recognized by @code{plotdf} are the following:
118
Option: @code{tstep} defines the length of the increments on the
119
independent variable @var{t}, used to compute an integral curve. If only
120
one expression @var{dydx} is given to @code{plotdf}, the @var{x}
121
variable will be directly proportional to @var{t}: @code{x - xinitial =
126
The default value is 0.1.
129
Option: @code{nsteps} defines the number of steps of length @code{tstep}
130
that will be used for the independent variable, to compute an integral
135
The default value is 100.
138
Option: @code{direction} defines the direction of the independent
139
variable that will be followed to compute an integral curve. Possible
140
values are @code{forward}, to make the independent variable increase
141
@code{nsteps} times, with increments @code{tstep}, @code{backward}, to
142
make the independent variable decrease, or @code{both} that will lead to
143
an integral curve that extends @code{nsteps} forward, and @code{nsteps}
144
backward. The keywords @code{right} and @code{left} can be used as
145
synonyms for @code{forward} and @code{backward}.
149
The defaul value is @code{both}.
152
Option: @code{tinitial} defines the initial value of variable @var{t} used
153
to compute integral curves. Since the differential equations are
154
autonomous, that setting will only appear in the plot of the curves as
155
functions of @var{t}.
159
The default value is 0.
162
Option: @code{versus_t} is used to create a second plot window, with a
163
plot of an integral curve, as two functions @var{x}, @var{y}, of the
164
independent variable @var{t}. If @code{versus_t} is given any value
165
different from 0, the second plot window will be displayed. The second
166
plot window includes another menu, similar to the menu of the main plot
171
The default value is 0.
174
Option: @code{trajectory_at} defines the coordinates @var{xinitial} and
175
@var{yinitial} for the starting point of an integral curve.
177
[trajectory_at,0.1,3.2]
179
The option is empty by default.
182
Option @code{parameters} defines a list of parameters, and their
183
numerical values, used in the definition of the differential
184
equations. The name and values of the parameters must be given in a
185
string with a comma-separated sequence of pairs @code{name=value}.
187
[parameters,"k=1.1,m=2.5"]
191
Option: @code{sliders} defines a list o parameters that will be changed
192
interactively using slider buttons, and the range of variation of those
193
parameters. The names and ranges of the parameters must be given in a
194
string with a comma-separated sequence of elements @code{name=min:max}
196
[sliders,"k=0:4,m=1:3"]
200
Option: @code{xfun} defines a string with semi-colon-separated sequence
201
of functions of @var{x} to be displayed, on top of the direction field.
202
Those functions will be parsed by Tcl and not by Maxima.
204
[xfun,"x^2;sin(x);exp(x)"]
208
Option: @code{xradius} is half of the length of the range of values that
209
will be shown in the x direction.
213
the default value is 10.
216
Option: @code{yradius} is half of the length of the range of values that
217
will be shown in the y direction.
221
the default value is 10.
224
Option: @code{xcenter} is the x coordinate of the point at the center of
229
The default value is 0.
232
Option: @code{ycenter} is the y coordinate of the point at the center of
237
The default value is 0.
240
Option: @code{width} defines the width of the plot window, in pixels.
244
The default value is 500.
247
Option: @code{height} defines the height of the plot window, in pixels.
251
The default value is 500.
256
NOTE: Due to a bug in @code{openmath}, all commands that use it, in particular
257
@code{plotdf}, must end with a semicolon and not with a dollar sign. The
258
dollar sign might work in some of the graphical interfaces to Maxima, but
259
to avoid problems we will use a semicolon in all the examples below.
263
To show the direction field of the differential equation @math{y' = exp(-x) + y} and the solution that goes through @math{(2, -0.1)}:
265
(%i1) load("plotdf")$
267
(%i2) plotdf(exp(-x)+y,[trajectory_at,2,-0.1]);
271
@image{figures/plotdf1,8cm}
275
To obtain the direction field for the equation @math{diff(y,x) = x - y^2} and the solution with initial condition @math{y(-1) = 3}, we can use the command:
277
(%i3) plotdf(x-y^2,[xfun,"sqrt(x);-sqrt(x)"],
278
[trajectory_at,-1,3], [direction,forward],
279
[yradius,5],[xcenter,6]);
281
The graph also shows the function @math{y = sqrt(x)}.
284
@image{figures/plotdf2,8cm}
288
The following example shows the direction field of a harmonic oscillator,
289
defined by the two equations @math{dx/dt = y} and @math{dy/dt = -k*x/m},
290
and the integral curve through @math{(x,y) = (6,0)}, with a slider that
291
will allow you to change the value of @math{m} interactively (@math{k} is
294
(%i4) plotdf([y,-k*x/m],[parameters,"m=2,k=2"],
295
[sliders,"m=1:5"], [trajectory_at,6,0]);
299
@image{figures/plotdf3,8cm}
303
To plot the direction field of the Duffing equation, @math{m*x''+c*x'+k*x+b*x^3 = 0}, we introduce the variable @math{y=x'} and use:
305
(%i5) plotdf([y,-(k*x + c*y + b*x^3)/m],
306
[parameters,"k=-1,m=1.0,c=0,b=1"],
307
[sliders,"k=-2:2,m=-1:1"],[tstep,0.1]);
311
@image{figures/plotdf4,8cm}
315
The direction field for a damped pendulum, including the
316
solution for the given initial conditions, with a slider that
317
can be used to change the value of the mass @math{m}, and with a plot of
318
the two state variables as a function of time:
321
(%i6) plotdf([y,-g*sin(x)/l - b*y/m/l],
322
[parameters,"g=9.8,l=0.5,m=0.3,b=0.05"],
323
[trajectory_at,1.05,-9],[tstep,0.01],
324
[xradius,6],[yradius,14],
325
[xcenter,-4],[direction,forward],[nsteps,300],
326
[sliders,"m=0.1:1"], [versus_t,1]);
330
@image{figures/plotdf5,8cm}@image{figures/plotdf6,8cm}
335
To use this function write first @code{load("plotdf")}.