1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on April, 24 2010 by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>
-->
<head>
<title>Maxima 5.21.1 Manual: 68. plotdf</title>
<meta name="description" content="Maxima 5.21.1 Manual: 68. plotdf">
<meta name="keywords" content="Maxima 5.21.1 Manual: 68. plotdf">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
body
{
color: black;
background: white;
margin-left: 8%;
margin-right: 13%;
}
h1
{
margin-left: +8%;
font-size: 150%;
font-family: sans-serif
}
h2
{
font-size: 125%;
font-family: sans-serif
}
h3
{
font-size: 100%;
font-family: sans-serif
}
h2,h3,h4,h5,h6 { margin-left: +4%; }
div.textbox
{
border: solid;
border-width: thin;
/* width: 100%; */
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em
}
div.titlebox
{
border: none;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em;
background: rgb(200,255,255);
font-family: sans-serif
}
div.synopsisbox
{
border: none;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em;
background: rgb(255,220,255);
/*background: rgb(200,255,255); */
/* font-family: fixed */
}
pre.example
{
border: 1px solid gray;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
/* background: rgb(247,242,180); */ /* kind of sandy */
/* background: rgb(200,255,255); */ /* sky blue */
background-color: #F1F5F9; /* light blue-gray */
/* font-family: "Lucida Console", monospace */
}
div.spacerbox
{
border: none;
padding-top: 2em;
padding-bottom: 2em
}
div.image
{
margin: 0;
padding: 1em;
text-align: center;
}
div.categorybox
{
border: 1px solid gray;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 1em;
padding-right: 1em;
background: rgb(247,242,220);
}
-->
</style>
<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="plotdf"></a>
<a name="SEC287"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_67.html#SEC286" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC288" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima_67.html#SEC278" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_69.html#SEC290" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 68. plotdf </h1>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC288">68.1 Introduction to plotdf</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC289">68.2 Functions and Variables for plotdf</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<p><a name="Item_003a-Introduction-to-plotdf"></a>
</p><hr size="6">
<a name="Introduction-to-plotdf"></a>
<a name="SEC288"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC287" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC289" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC287" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC287" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_69.html#SEC290" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 68.1 Introduction to plotdf </h2>
<p>The function <code>plotdf</code> creates a plot of the direction field of a
first-order Ordinary Differential Equation (ODE) or a system of two
autonomous first-order ODE's.
</p>
<p>Since this is an additional package, in order to use it you must first
load it with <code>load("plotdf")</code>. Plotdf requires Openmath, which is
provided by the package Xmaxima (Xmaxima is not only used as a graphical
console for Maxima but also to plot graphs in the Openmath format).
</p>
<p>To plot the direction field of a single ODE, the ODE must be written in
the form:
</p><pre class="example"> dy
-- = F(x,y)
dx
</pre>
<p>and the function <var>F</var> should be given as the argument for
<code>plotdf</code>. If the independent and dependent variables are not <var>x</var>,
and <var>y</var>, as in the equation above, then those two variables should
be named explicitly in a list given as an argument to the plotdf command
(see the examples).
</p>
<p>To plot the direction field of a set of two autonomous ODE's, they must
be written in the form
</p><pre class="example"> dx dy
-- = G(x,y) -- = F(x,y)
dt dt
</pre>
<p>and the argument for <code>plotdf</code> should be a list with the two
functions <var>G</var> and <var>F</var>, in that order; namely, the first
expression in the list will be taken to be the time derivative of the
variable represented on the horizontal axis, and the second expression
will be the time derivative of the variable represented on the vertical
axis. Those two variables do not have to be <var>x</var> and <var>y</var>, but if
they are not, then the second argument given to plotdf must be another
list naming the two variables, first the one on the horizontal axis and
then the one on the vertical axis.
</p>
<p>If only one ODE is given, <code>plotdf</code> will implicitly admit
<code>x=t</code>, and <code>G(x,y)=1</code>, transforming the non-autonomous
equation into a system of two autonomous equations.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_95.html#Category_003a-Differential-equations">Differential equations</a>
·
<a href="maxima_95.html#Category_003a-Share-packages">Share packages</a>
·
<a href="maxima_95.html#Category_003a-Package-plotdf">Package plotdf</a>
</p>
</div>
<p><a name="Item_003a-Functions-and-Variables-for-plotdf"></a>
</p><hr size="6">
<a name="Functions-and-Variables-for-plotdf"></a>
<a name="SEC289"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC288" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="maxima_69.html#SEC290" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC287" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC287" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_69.html#SEC290" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 68.2 Functions and Variables for plotdf </h2>
<dl>
<dt><u>Function:</u> <b>plotdf</b><i> (<var>dydx</var>, ...options...)</i>
<a name="IDX2425"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<var>dvdu</var>, <code>[</code><var>u</var>,<var>v</var><code>]</code>, ...options...)</i>
<a name="IDX2426"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<code>[</code><var>dxdt</var>,<var>dydt</var><code>]</code>, ...options...)</i>
<a name="IDX2427"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<code>[</code><var>dudt</var>,<var>dvdt</var><code>]</code>, <code>[</code><var>u</var>,<var>v</var><code>]</code>, ...options...)</i>
<a name="IDX2428"></a>
</dt>
<dd><p>Displays a direction field in two dimensions <var>x</var> and <var>y</var>.
</p>
<p><var>dydx</var>, <var>dxdt</var> and <var>dydt</var> are expressions that depend on
<var>x</var> and <var>y</var>. <var>dvdu</var>, <var>dudt</var> and <var>dvdt</var> are
expressions that depend on <var>u</var> and <var>v</var>. In addition to those two
variables, the expressions can also depend on a set of parameters, with
numerical values given with the <code>parameters</code> option (the option
syntax is given below), or with a range of allowed values specified by a
<var>sliders</var> option.
</p>
<p>Several other options can be given within the command, or selected in
the menu. Integral curves can be obtained by clicking on the plot, or
with the option <code>trajectory_at</code>. The direction of the integration
can be controlled with the <code>direction</code> option, which can have
values of <em>forward</em>, <em>backward</em> or <em>both</em>. The number of
integration steps is given by <code>nsteps</code> and the time interval
between them is set up with the <code>tstep</code> option. The Adams Moulton
method is used for the integration; it is also possible to switch to an
adaptive Runge-Kutta 4th order method.
</p>
<p><b>Plot window menu:</b>
</p>
<p>The menu in the plot window has the following options: <em>Zoom</em>, will
change the behavior of the mouse so that it will allow you to zoom in on
a region of the plot by clicking with the left button. Each click near a
point magnifies the plot, keeping the center at the point where you
clicked. Holding the <kbd>Shift</kbd> key while clicking, zooms out to the
previous magnification. To resume computing trajectories when you click
on a point, select <em>Integrate</em> from the menu.
</p>
<p>The option <em>Config</em> in the menu can be used to change the ODE(s) in
use and various other settings. After configuration changes are made,
the menu option <em>Replot</em> should be selected, to activate the new
settings. If a pair of coordinates are entered in the field
<em>Trajectory at</em> in the <em>Config</em> dialog menu, and the
<kbd>enter</kbd> key is pressed, a new integral curve will be shown, in
addition to the ones already shown. When <em>Replot</em> is selected, only
the last integral curve entered will be shown.
</p>
<p>Holding the right mouse button down while the cursor is moved, can be
used to drag the plot sideways or up and down. Additional
parameters such as the number of steps, the initial value of <var>t</var>
and the x and y centers and radii, may be set in the Config menu.
</p>
<p>A copy of the plot can be saved as a postscript file, using the menu
option <em>Save</em>.
</p>
<p><b>Plot options:</b>
</p>
<p>The <code>plotdf</code> command may include several commands, each command is
a list of two or more items. The first item is the name of the option,
and the remainder comprises the value or values assigned to the option.
</p>
<p>The options which are recognized by <code>plotdf</code> are the following:
</p>
<ul>
<li>
<em>tstep</em> defines the length of the increments on the
independent variable <var>t</var>, used to compute an integral curve. If only
one expression <var>dydx</var> is given to <code>plotdf</code>, the <var>x</var>
variable will be directly proportional to <var>t</var>.
The default value is 0.1.
</li><li>
<em>nsteps</em> defines the number of steps of length <code>tstep</code>
that will be used for the independent variable, to compute an integral
curve.
The default value is 100.
</li><li>
<em>direction</em> defines the direction of the independent
variable that will be followed to compute an integral curve. Possible
values are <code>forward</code>, to make the independent variable increase
<code>nsteps</code> times, with increments <code>tstep</code>, <code>backward</code>, to
make the independent variable decrease, or <code>both</code> that will lead to
an integral curve that extends <code>nsteps</code> forward, and <code>nsteps</code>
backward. The keywords <code>right</code> and <code>left</code> can be used as
synonyms for <code>forward</code> and <code>backward</code>.
The default value is <code>both</code>.
</li><li>
<em>tinitial</em> defines the initial value of variable <var>t</var> used
to compute integral curves. Since the differential equations are
autonomous, that setting will only appear in the plot of the curves as
functions of <var>t</var>.
The default value is 0.
</li><li>
<em>versus_t</em> is used to create a second plot window, with a
plot of an integral curve, as two functions <var>x</var>, <var>y</var>, of the
independent variable <var>t</var>. If <code>versus_t</code> is given any value
different from 0, the second plot window will be displayed. The second
plot window includes another menu, similar to the menu of the main plot
window.
The default value is 0.
</li><li>
<em>trajectory_at</em> defines the coordinates <var>xinitial</var> and
<var>yinitial</var> for the starting point of an integral curve.
The option is empty by default.
</li><li>
<em>parameters</em> defines a list of parameters, and their
numerical values, used in the definition of the differential
equations. The name and values of the parameters must be given in a
string with a comma-separated sequence of pairs <code>name=value</code>.
</li><li>
<em>sliders</em> defines a list of parameters that will be changed
interactively using slider buttons, and the range of variation of those
parameters. The names and ranges of the parameters must be given in a
string with a comma-separated sequence of elements <code>name=min:max</code>
</li><li>
<em>xfun</em> defines a string with semi-colon-separated sequence
of functions of <var>x</var> to be displayed, on top of the direction field.
Those functions will be parsed by Tcl and not by Maxima.
</li><li>
<em>x</em> should be followed by two numbers, which will set up the minimum
and maximum values shown on the horizontal axis. If the variable on the
horizontal axis is not <var>x</var>, then this option should have the name of
the variable on the horizontal axis.
The default horizontal range is from -10 to 10.
</li><li>
<em>y</em> should be followed by two numbers, which will set up the minimum
and maximum values shown on the vertical axis. If the variable on the
vertical axis is not <var>y</var>, then this option should have the name of
the variable on the vertical axis.
The default vertical range is from -10 to 10.
</li></ul>
<p><b>Examples:</b>
</p>
<ul>
<li>
To show the direction field of the differential equation <em>y' = exp(-x) + y</em> and the solution that goes through <em>(2, -0.1)</em>:
<pre class="example">(%i1) load("plotdf")$
(%i2) plotdf(exp(-x)+y,[trajectory_at,2,-0.1])$
</pre>
<p><div class="image"><img src="./figures/plotdf1.gif" alt="figures/plotdf1"></div>
</p>
</li><li>
To obtain the direction field for the equation <em>diff(y,x) = x - y^2</em> and the solution with initial condition <em>y(-1) = 3</em>, we can use the command:
<pre class="example">(%i3) plotdf(x-y^2,[xfun,"sqrt(x);-sqrt(x)"],
[trajectory_at,-1,3], [direction,forward],
[y,-5,5], [x,-4,16])$
</pre><p>The graph also shows the function <em>y = sqrt(x)</em>.
</p>
<p><div class="image"><img src="./figures/plotdf2.gif" alt="figures/plotdf2"></div>
</p>
</li><li>
The following example shows the direction field of a harmonic oscillator,
defined by the two equations <em>dz/dt = v</em> and <em>dv/dt = -k*z/m</em>,
and the integral curve through <em>(z,v) = (6,0)</em>, with a slider that
will allow you to change the value of <em>m</em> interactively (<em>k</em> is
fixed at 2):
<pre class="example">(%i4) plotdf([v,-k*z/m], [z,v], [parameters,"m=2,k=2"],
[sliders,"m=1:5"], [trajectory_at,6,0])$
</pre>
<p><div class="image"><img src="./figures/plotdf3.gif" alt="figures/plotdf3"></div>
</p>
</li><li>
To plot the direction field of the Duffing equation, <em>m*x"+c*x'+k*x+b*x^3 = 0</em>, we introduce the variable <em>y=x'</em> and use:
<pre class="example">(%i5) plotdf([y,-(k*x + c*y + b*x^3)/m],
[parameters,"k=-1,m=1.0,c=0,b=1"],
[sliders,"k=-2:2,m=-1:1"],[tstep,0.1])$
</pre>
<p><div class="image"><img src="./figures/plotdf4.gif" alt="figures/plotdf4"></div>
</p>
</li><li>
The direction field for a damped pendulum, including the
solution for the given initial conditions, with a slider that
can be used to change the value of the mass <em>m</em>, and with a plot of
the two state variables as a function of time:
<pre class="example">(%i6) plotdf([w,-g*sin(a)/l - b*w/m/l], [a,w],
[parameters,"g=9.8,l=0.5,m=0.3,b=0.05"],
[trajectory_at,1.05,-9],[tstep,0.01],
[a,-10,2], [w,-14,14], [direction,forward],
[nsteps,300], [sliders,"m=0.1:1"], [versus_t,1])$
</pre>
<p><div class="image"><img src="./figures/plotdf5.gif" alt="figures/plotdf5"></div><div class="image"><img src="./figures/plotdf6.gif" alt="figures/plotdf6"></div>
</p>
</li></ul>
<div class=categorybox>
<p>Categories: <a href="maxima_95.html#Category_003a-Package-plotdf">Package plotdf</a>
·
<a href="maxima_95.html#Category_003a-Plotting">Plotting</a>
·
<a href="maxima_95.html#Category_003a-Numerical-methods">Numerical methods</a>
</p>
</div>
</dd></dl>
<p><a name="Item_003a-romberg"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC287" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="maxima_69.html#SEC290" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>Robert Dodier</em> on <em>April, 24 2010</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
</font>
<br>
</p>
</body>
</html>
|