1 @c -----------------------------------------------------------------------------
2 @c File : drawdf.de.texi
3 @c License : GNU General Public License (GPL)
5 @c Original : drawdf.texi revision 1.2
8 @c This file is part of Maxima -- GPL CAS based on DOE-MACSYMA
9 @c -----------------------------------------------------------------------------
12 * Introduction to drawdf::
13 * Functions and Variables for drawdf::
16 @c -----------------------------------------------------------------------------
17 @node Introduction to drawdf, Functions and Variables for drawdf, drawdf, drawdf
18 @section Introduction to drawdf
20 The function @code{drawdf} draws the direction field of a first-order
21 Ordinary Differential Equation (ODE) or a system of two autonomous
24 Since this is an additional package, in order to use it you must first
25 load it with @code{load("drawdf")}. Drawdf is built upon the @code{draw}
26 package, which requires Gnuplot 4.2.
28 To plot the direction field of a single ODE, the ODE must be written in
38 $${{dy}\over{dx}} = F(x,y)$$
41 and the function @var{F} should be given as the argument for
42 @code{drawdf}. If the independent and dependent variables are not @var{x},
43 and @var{y}, as in the equation above, then those two variables should
44 be named explicitly in a list given as an argument to the drawdf command
47 To plot the direction field of a set of two autonomous ODE's, they must
48 be written in the form
52 -- = G(x,y) -- = F(x,y)
57 $${{dx}\over{dt}} = G(x,y) \qquad {{dy}\over{dt}} = F(x,y)$$
60 and the argument for @code{drawdf} should be a list with the two
61 functions @var{G} and @var{F}, in that order; namely, the first
62 expression in the list will be taken to be the time derivative of the
63 variable represented on the horizontal axis, and the second expression
64 will be the time derivative of the variable represented on the vertical
65 axis. Those two variables do not have to be @var{x} and @var{y}, but if
66 they are not, then the second argument given to drawdf must be another
67 list naming the two variables, first the one on the horizontal axis and
68 then the one on the vertical axis.
70 If only one ODE is given, @code{drawdf} will implicitly admit
71 @code{x=t}, and @code{G(x,y)=1}, transforming the non-autonomous
72 equation into a system of two autonomous equations.
75 @c @category{Differential equations} @category{Plotting}
76 @c @category{Share packages} @category{Package drawdf}
77 @c @category{Package draw}
80 @c -----------------------------------------------------------------------------
81 @node Functions and Variables for drawdf, , Introduction to drawdf, drawdf
82 @section Functions and Variables for drawdf
84 @c -----------------------------------------------------------------------------
87 @c -----------------------------------------------------------------------------
88 @anchor{function_drawdf}
89 @deffn {Function} drawdf (@var{dydx}, ...options and objects...)
90 @deffnx {Function} drawdf (@var{dvdu}, @code{[}@var{u},@var{v}@code{]}, ...options and objects...)
91 @deffnx {Function} drawdf (@var{dvdu}, @code{[}@var{u},@var{umin},@var{umax}@code{]}, @code{[}@var{v},@var{vmin},@var{vmax}@code{]}, ...options and objects...)
92 @deffnx {Function} drawdf (@code{[}@var{dxdt},@var{dydt}@code{]}, ...options and objects...)
93 @deffnx {Function} drawdf (@code{[}@var{dudt},@var{dvdt}@code{]}, @code{[}@var{u},@var{v}@code{]}, ...options and objects...)
94 @deffnx {Function} drawdf (@code{[}@var{dudt},@var{dvdt}@code{]}, @code{[}@var{u},@var{umin},@var{umax}@code{]}, @code{[}@var{v},@var{vmin},@var{vmax}@code{]}, ...options and objects...)
96 Function @code{drawdf} draws a 2D direction field with optional
97 solution curves and other graphics using the @code{draw} package.
99 The first argument specifies the derivative(s), and must be either an
100 expression or a list of two expressions. @var{dydx}, @var{dxdt} and
101 @var{dydt} are expressions that depend on @var{x} and @var{y}.
102 @var{dvdu}, @var{dudt} and @var{dvdt} are expressions that depend on
105 If the independent and dependent variables are not @var{x} and
106 @var{y}, then their names must be specified immediately following the
107 derivative(s), either as a list of two names
108 @code{[}@var{u},@var{v}@code{]}, or as two lists of the form
109 @code{[}@var{u},@var{umin},@var{umax}@code{]} and
110 @code{[}@var{v},@var{vmin},@var{vmax}@code{]}.
112 The remaining arguments are @i{graphic options}, @i{graphic objects},
113 or lists containing graphic options and objects, nested to arbitrary
114 depth. The set of graphic options and objects supported by
115 @code{drawdf} is a superset of those supported by @code{draw2d} and
116 @code{gr2d} from the @code{draw} package.
118 The arguments are interpreted sequentially: @i{graphic options} affect
119 all following @i{graphic objects}. Furthermore, @i{graphic objects}
120 are drawn on the canvas in order specified, and may obscure graphics
121 drawn earlier. Some @i{graphic options} affect the global appearence
124 The additional @i{graphic objects} supported by @code{drawdf} include:
125 @code{solns_at}, @code{points_at}, @code{saddles_at}, @code{soln_at},
126 @code{point_at}, and @code{saddle_at}.
128 The additional @i{graphic options} supported by @code{drawdf} include:
129 @code{field_degree}, @code{soln_arrows}, @code{field_arrows},
130 @code{field_grid}, @code{field_color}, @code{show_field},
131 @code{tstep}, @code{nsteps}, @code{duration}, @code{direction},
132 @code{field_tstep}, @code{field_nsteps}, and @code{field_duration}.
134 Commonly used @i{graphic objects} inherited from the @code{draw}
135 package include: @code{explicit}, @code{implicit}, @code{parametric},
136 @code{polygon}, @code{points}, @code{vector}, @code{label}, and all
137 others supported by @code{draw2d} and @code{gr2d}.
139 Commonly used @i{graphic options} inherited from the @code{draw}
142 @code{points_joined}, @code{color},
143 @code{point_type}, @code{point_size}, @code{line_width},
144 @code{line_type}, @code{key}, @code{title}, @code{xlabel},
145 @code{ylabel}, @code{user_preamble}, @code{terminal},
146 @code{dimensions}, @code{file_name}, and all
147 others supported by @code{draw2d} and @code{gr2d}.
150 See also @code{draw2d}.
152 Users of wxMaxima or Imaxima may optionally use @code{wxdrawdf}, which
153 is identical to @code{drawdf} except that the graphics are drawn
154 within the notebook using @code{wxdraw}.
156 To make use of this function, write first @code{load("drawdf")}.
161 (%i1) load("drawdf")$
162 (%i2) drawdf(exp(-x)+y)$ /* default vars: x,y */
163 (%i3) drawdf(exp(-t)+y, [t,y])$ /* default range: [-10,10] */
164 (%i4) drawdf([y,-9*sin(x)-y/5], [x,1,5], [y,-2,2])$
167 For backward compatibility, @code{drawdf} accepts
168 most of the parameters supported by plotdf.
171 (%i5) drawdf(2*cos(t)-1+y, [t,y], [t,-5,10], [y,-4,9],
172 [trajectory_at,0,0])$
175 @code{soln_at} and @code{solns_at} draw solution curves
176 passing through the specified points, using a slightly
177 enhanced 4th-order Runge Kutta numerical integrator.
180 (%i6) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
181 solns_at([0,0.1],[0,-0.1]),
182 color=blue, soln_at(0,0))$
185 @code{field_degree=2} causes the field to be composed of quadratic
186 splines, based on the first and second derivatives at each grid point.
187 @code{field_grid=[}@var{COLS},@var{ROWS}@code{]} specifies the number
188 of columns and rows in the grid.
191 (%i7) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
192 field_degree=2, field_grid=[20,15],
193 solns_at([0,0.1],[0,-0.1]),
194 color=blue, soln_at(0,0))$
197 @code{soln_arrows=true} adds arrows to the solution curves, and (by
198 default) removes them from the direction field. It also changes the
199 default colors to emphasize the solution curves.
202 (%i8) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
204 solns_at([0,0.1],[0,-0.1],[0,0]))$
207 @code{duration=40} specifies the time duration of numerical
208 integration (default 10). Integration will also stop automatically if
209 the solution moves too far away from the plotted region, or if the
210 derivative becomes complex or infinite. Here we also specify
211 @code{field_degree=2} to plot quadratic splines. The equations below
212 model a predator-prey system.
215 (%i9) drawdf([x*(1-x-y), y*(3/4-y-x/2)], [x,0,1.1], [y,0,1],
216 field_degree=2, duration=40,
217 soln_arrows=true, point_at(1/2,1/2),
218 solns_at([0.1,0.2], [0.2,0.1], [1,0.8], [0.8,1],
219 [0.1,0.1], [0.6,0.05], [0.05,0.4],
220 [1,0.01], [0.01,0.75]))$
223 @code{field_degree='solns} causes the field to be composed
224 of many small solution curves computed by 4th-order
225 Runge Kutta, with better results in this case.
228 (%i10) drawdf([x*(1-x-y), y*(3/4-y-x/2)], [x,0,1.1], [y,0,1],
229 field_degree='solns, duration=40,
230 soln_arrows=true, point_at(1/2,1/2),
231 solns_at([0.1,0.2], [0.2,0.1], [1,0.8],
232 [0.8,1], [0.1,0.1], [0.6,0.05],
233 [0.05,0.4], [1,0.01], [0.01,0.75]))$
236 @code{saddles_at} attempts to automatically linearize the equation at
237 each saddle, and to plot a numerical solution corresponding to each
238 eigenvector, including the separatrices. @code{tstep=0.05} specifies
239 the maximum time step for the numerical integrator (the default is
240 0.1). Note that smaller time steps will sometimes be used in order to
241 keep the x and y steps small. The equations below model a damped
245 (%i11) drawdf([y,-9*sin(x)-y/5], tstep=0.05,
246 soln_arrows=true, point_size=0.5,
247 points_at([0,0], [2*%pi,0], [-2*%pi,0]),
249 saddles_at([%pi,0], [-%pi,0]))$
252 @code{show_field=false} suppresses the field entirely.
255 (%i12) drawdf([y,-9*sin(x)-y/5], tstep=0.05,
256 show_field=false, soln_arrows=true,
258 points_at([0,0], [2*%pi,0], [-2*%pi,0]),
259 saddles_at([3*%pi,0], [-3*%pi,0],
263 @code{drawdf} passes all unrecognized parameters to @code{draw2d} or
264 @code{gr2d}, allowing you to combine the full power of the @code{draw}
265 package with @code{drawdf}.
268 (%i13) drawdf(x^2+y^2, [x,-2,2], [y,-2,2], field_color=gray,
269 key="soln 1", color=black, soln_at(0,0),
270 key="soln 2", color=red, soln_at(0,1),
271 key="isocline", color=green, line_width=2,
272 nticks=100, parametric(cos(t),sin(t),t,0,2*%pi))$
275 @code{drawdf} accepts nested lists of graphic options and objects,
276 allowing convenient use of makelist and other function calls to
280 (%i14) colors : ['red,'blue,'purple,'orange,'green]$
281 (%i15) drawdf([x-x*y/2, (x*y - 3*y)/4],
282 [x,2.5,3.5], [y,1.5,2.5],
284 makelist([ key = concat("soln",k),
286 soln_at(3, 2 + k/20) ],
291 @c @category{Package drawdf}
295 @c --- End of file draw.de.texi ------------------------------------------------