Maxima 5.38.1 http://maxima.sourceforge.net using Lisp CLISP 2.49 (2010-07-07) Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. The function bug_report() provides bug reporting information. (%i1) batch("help.mac") read and interpret file: /home/nn/Dropbox/tmp/ktisku/help.mac (%i2) describe("plotdf",exact) -- Function: plotdf plotdf (, options...) plotdf (, [,], options...) plotdf ([,c], options...) plotdf ([,c], [,c], options...) The function 'plotdf' creates a two-dimensional plot of the direction field (also called slope field) for a first-order Ordinary Differential Equation (ODE) or a system of two autonomous first-order ODE's. Plotdf requires Xmaxima, even if its run from a Maxima session in a console, since the plot will be created by the Tk scripts in Xmaxima. If Xmaxima is not installed plotdf will not work. , and are expressions that depend on and . , and are expressions that depend on and . In addition to those two variables, the expressions can also depend on a set of parameters, with numerical values given with the 'parameters' option (the option syntax is given below), or with a range of allowed values specified by a option. 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 'trajectory_at'. The direction of the integration can be controlled with the 'direction' option, which can have values of _forward_, _backward_ or _both_. The number of integration steps is given by 'nsteps'; at each integration step the time increment will be adjusted automatically to produce displacements much smaller than the size of the plot window. The numerical method used is 4th order Runge-Kutta with variable time steps. Plot window menu: The menu bar of the plot window has the following seven icons: An X. Can be used to close the plot window. A wrench and a screwdriver. Opens the configuration menu with several fields that show the ODE(s) in use and various other settings. If a pair of coordinates are entered in the field _Trajectory at_ and the key is pressed, a new integral curve will be shown, in addition to the ones already shown. Two arrows following a circle. Replots the direction field with the new settings defined in the configuration menu and replots only the last integral curve that was previously plotted. Hard disk drive with an arrow. Used to save a copy of the plot, in Postscript format, in the file specified in a field of the box that appears when that icon is clicked. Magnifying glass with a plus sign. Zooms in the plot. Magnifying glass with a minus sign. Zooms out the plot. The plot can be displaced by holding down the right mouse button while the mouse is moved. Icon of a plot. Opens another window with a plot of the two variables in terms of time, for the last integral curve that was plotted. Plot options: Options can also be given within the 'plotdf' itself, each one being a list of two or more elements. The first element in each option is the name of the option, and the remainder is the value or values assigned to the option. The options which are recognized by 'plotdf' are the following: * "nsteps" defines the number of steps that will be used for the independent variable, to compute an integral curve. The default value is 100. * "direction" defines the direction of the independent variable that will be followed to compute an integral curve. Possible values are 'forward', to make the independent variable increase 'nsteps' times, with increments 'tstep', 'backward', to make the independent variable decrease, or 'both' that will lead to an integral curve that extends 'nsteps' forward, and 'nsteps' backward. The keywords 'right' and 'left' can be used as synonyms for 'forward' and 'backward'. The default value is 'both'. * "tinitial" defines the initial value of variable 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 . The default value is 0. * "versus_t" is used to create a second plot window, with a plot of an integral curve, as two functions , , of the independent variable . If 'versus_t' 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. * "trajectory_at" defines the coordinates and for the starting point of an integral curve. The option is empty by default. * "parameters" 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 'name=value'. * "sliders" 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 'name=min:max' * "xfun" defines a string with semi-colon-separated sequence of functions of to be displayed, on top of the direction field. Those functions will be parsed by Tcl and not by Maxima. * "x" 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 , then this option should have the name of the variable on the horizontal axis. The default horizontal range is from -10 to 10. * "y" 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 , then this option should have the name of the variable on the vertical axis. The default vertical range is from -10 to 10. * "xaxislabel" will be used to identify the horizontal axis. Its default value is the name of the first state variable. * "yaxislabel" will be used to identify the vertical axis. Its default value is the name of the second state variable. *Examples:* * To show the direction field of the differential equation y' = exp(-x) + y and the solution that goes through (2, -0.1): (%i1) plotdf(exp(-x)+y,[trajectory_at,2,-0.1])$ * To obtain the direction field for the equation diff(y,x) = x - y^2 and the solution with initial condition y(-1) = 3, we can use the command: (%i1) plotdf(x-y^2,[xfun,"sqrt(x);-sqrt(x)"], [trajectory_at,-1,3], [direction,forward], [y,-5,5], [x,-4,16])$ The graph also shows the function y = sqrt(x). * The following example shows the direction field of a harmonic oscillator, defined by the two equations dz/dt = v and dv/dt = -k*z/m, and the integral curve through (z,v) = (6,0), with a slider that will allow you to change the value of m interactively (k is fixed at 2): (%i1) plotdf([v,-k*z/m], [z,v], [parameters,"m=2,k=2"], [sliders,"m=1:5"], [trajectory_at,6,0])$ * To plot the direction field of the Duffing equation, m*x''+c*x'+k*x+b*x^3 = 0, we introduce the variable y=x' and use: (%i1) 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])$ * 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 m, and with a plot of the two state variables as a function of time: (%i1) 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])$ (%o2) true (%o2) help.mac