~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to doc/info/plotdf.texi

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@menu
 
2
* Introduction to plotdf::
 
3
* Definitions for plotdf::
 
4
@end menu
 
5
 
 
6
@node Introduction to plotdf, Definitions for plotdf, plotdf, plotdf
 
7
@section Introduction to plotdf
 
8
 
 
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.
 
12
 
 
13
To plot the direction field of a single ODE, the ODE must be written in
 
14
the form:
 
15
@ifnottex
 
16
@example
 
17
       dy
 
18
       -- = F(x,y)
 
19
       dx
 
20
@end example
 
21
@end ifnottex
 
22
@tex
 
23
$${{dy}\over{dx}} = F(x,y)$$
 
24
@end tex
 
25
 
 
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.
 
30
 
 
31
To plot the direction field of a set of two autonomous ODE's, they must
 
32
be written in the form
 
33
@ifnottex
 
34
@example
 
35
       dx             dy
 
36
       -- = G(x,y)    -- = F(x,y) 
 
37
       dt             dt
 
38
@end example
 
39
@end ifnottex
 
40
@tex
 
41
$${{dx}\over{dt}} = G(x,y) \qquad {{dy}\over{dt}} = F(x,y)$$
 
42
@end tex
 
43
 
 
44
and the argument for @code{plotdf} should be a list with the two
 
45
functions @var{F} and @var{G}, in any order.
 
46
 
 
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.
 
50
 
 
51
@node Definitions for plotdf,  , Introduction to plotdf, plotdf
 
52
@section Definitions for plotdf
 
53
 
 
54
@deffn {Function} plotdf (@var{dydx},...options...)
 
55
@deffnx {Function} plotdf (@code{[}@var{dxdt},@var{dydt}@code{]},...options...)
 
56
 
 
57
Displays a direction field in two dimensions @var{x} and @var{y}.
 
58
 
 
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
 
64
@var{sliders} option.
 
65
 
 
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
 
75
4th order method.
 
76
 
 
77
@b{Plot window menu:}
 
78
 
 
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.
 
86
 
 
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
 
94
shown.
 
95
 
 
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.
 
100
 
 
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.
 
107
 
 
108
@b{Plot options:}
 
109
 
 
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.
 
113
 
 
114
The options which are recognized by @code{plotdf} are the following:
 
115
 
 
116
@itemize @bullet
 
117
@item
 
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 =
 
122
t - tinitial}.
 
123
@example
 
124
[tstep,0.01]
 
125
@end example
 
126
The default value is 0.1.
 
127
 
 
128
@item
 
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
 
131
curve.
 
132
@example
 
133
[nsteps,500]
 
134
@end example
 
135
The default value is 100.
 
136
 
 
137
@item
 
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}.
 
146
@example
 
147
[direction,forward]
 
148
@end example
 
149
The defaul value is @code{both}.
 
150
 
 
151
@item
 
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}. 
 
156
@example
 
157
[tinitial,6.7]
 
158
@end example
 
159
The default value is 0.
 
160
 
 
161
@item
 
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
 
167
window.
 
168
@example
 
169
[versus_t,1]
 
170
@end example
 
171
The default value is 0.
 
172
 
 
173
@item
 
174
Option: @code{trajectory_at} defines the coordinates @var{xinitial} and
 
175
@var{yinitial} for the starting point of an integral curve.
 
176
@example
 
177
[trajectory_at,0.1,3.2]
 
178
@end example
 
179
The option is empty by default.
 
180
 
 
181
@item
 
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}.
 
186
@example
 
187
[parameters,"k=1.1,m=2.5"]
 
188
@end example
 
189
 
 
190
@item
 
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}
 
195
@example
 
196
[sliders,"k=0:4,m=1:3"]
 
197
@end example
 
198
 
 
199
@item
 
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.
 
203
@example 
 
204
[xfun,"x^2;sin(x);exp(x)"]
 
205
@end example
 
206
 
 
207
@item
 
208
Option: @code{xradius} is half of the length of the range of values that
 
209
will be shown in the x direction.
 
210
@example
 
211
[xradius,12.5]
 
212
@end example
 
213
the default value is 10.
 
214
 
 
215
@item
 
216
Option: @code{yradius} is half of the length of the range of values that
 
217
will be shown in the y direction.
 
218
@example
 
219
[yradius,15]
 
220
@end example
 
221
the default value is 10.
 
222
 
 
223
@item
 
224
Option: @code{xcenter} is the x coordinate of the point at the center of
 
225
the plot.
 
226
@example
 
227
[xcenter,3.45]
 
228
@end example
 
229
The default value is 0.
 
230
 
 
231
@item
 
232
Option: @code{ycenter} is the y coordinate of the point at the center of
 
233
the plot.
 
234
@example
 
235
[ycenter,4.5]
 
236
@end example
 
237
The default value is 0.
 
238
 
 
239
@item
 
240
Option: @code{width} defines the width of the plot window, in pixels.
 
241
@example
 
242
[width,800]
 
243
@end example
 
244
The default value is 500.
 
245
 
 
246
@item
 
247
Option: @code{height} defines the height of the plot window, in pixels.
 
248
@example
 
249
[width,600]
 
250
@end example
 
251
The default value is 500.
 
252
@end itemize
 
253
 
 
254
@b{Examples:}
 
255
 
 
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.
 
260
  
 
261
@itemize @bullet
 
262
@item
 
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)}:
 
264
@example
 
265
(%i1) load("plotdf")$
 
266
 
 
267
(%i2) plotdf(exp(-x)+y,[trajectory_at,2,-0.1]);
 
268
@end example
 
269
 
 
270
@ifnotinfo
 
271
@image{figures/plotdf1,8cm}
 
272
@end ifnotinfo
 
273
 
 
274
@item
 
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:
 
276
@example
 
277
(%i3) plotdf(x-y^2,[xfun,"sqrt(x);-sqrt(x)"],
 
278
          [trajectory_at,-1,3], [direction,forward],
 
279
          [yradius,5],[xcenter,6]);
 
280
@end example
 
281
The graph also shows the function @math{y = sqrt(x)}. 
 
282
 
 
283
@ifnotinfo
 
284
@image{figures/plotdf2,8cm}
 
285
@end ifnotinfo
 
286
 
 
287
@item
 
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
 
292
fixed at 2):
 
293
@example
 
294
(%i4) plotdf([y,-k*x/m],[parameters,"m=2,k=2"],
 
295
            [sliders,"m=1:5"], [trajectory_at,6,0]);
 
296
@end example
 
297
 
 
298
@ifnotinfo
 
299
@image{figures/plotdf3,8cm}
 
300
@end ifnotinfo
 
301
 
 
302
@item
 
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:
 
304
@example
 
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]);
 
308
@end example
 
309
 
 
310
@ifnotinfo
 
311
@image{figures/plotdf4,8cm}
 
312
@end ifnotinfo
 
313
 
 
314
@item
 
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:
 
319
 
 
320
@example
 
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]);
 
327
@end example
 
328
 
 
329
@ifnotinfo
 
330
@image{figures/plotdf5,8cm}@image{figures/plotdf6,8cm}
 
331
@end ifnotinfo
 
332
 
 
333
@end itemize
 
334
 
 
335
To use this function write first @code{load("plotdf")}.
 
336
@end deffn
 
337