54. dynamics

54.1 The dynamics package

Package dynamics includes functions for 3D visualization,
animations, graphical analysis of differential and difference equations
and numerical solution of differential equations. The functions for
differential equations are described in the section on Numerical Methods and the functions to plot the Mandelbrot and Julia
sets are described in the section on Plotting.

All the functions in this package will be loaded automatically the first
time they are used.

54.2 Graphical analysis of discrete dynamical systems

Function:chaosgame ([[x1, y1]…[xm, ym]], [x0, y0], b, n, options, …);

Implements the so-called chaos game: the initial point (x0,
y0) is plotted and then one of the m points
[x1, y1]…xm, ym]
will be selected at random. The next point plotted will be on the
segment from the previous point plotted to the point chosen randomly, at a
distance from the random point which will be b times that segment's
length. The procedure is repeated n times. The options are the
same as for plot2d.

Draws n+1 points in a two-dimensional graph, where the horizontal
coordinates of the points are the integers 0, 1, 2, ..., n, and
the vertical coordinates are the corresponding values y(n) of the
sequence defined by the recurrence relation

y(n+1) = F(y(n))

With initial value y(0) equal to y0. F must be an
expression that depends only on one variable (in the example, it
depend on y, but any other variable can be used),
y0 must be a real number and n must be a positive integer.
This function accepts the same options as plot2d.

Implements the Iterated Function System method. This method is similar
to the method described in the function chaosgame. but instead of
shrinking the segment from the current point to the randomly chosen
point, the 2 components of that segment will be multiplied by the 2 by 2
matrix Ai that corresponds to the point chosen randomly.

The random choice of one of the m attractive points can be made
with a non-uniform probability distribution defined by the weights
r1,...,rm. Those weights are given in cumulative form; for
instance if there are 3 points with probabilities 0.2, 0.5 and 0.3, the
weights r1, r2 and r3 could be 2, 7 and 10. The
options are the same as for plot2d.

Draws the orbits diagram for a family of one-dimensional
discrete dynamical systems, with one parameter x; that kind of
diagram is used to study the bifurcations of a one-dimensional discrete
system.

The function F(y) defines a sequence with a starting value of
y0, as in the case of the function evolution, but in this
case that function will also depend on a parameter x that will
take values in the interval from x0 to xf with increments of
xstep. Each value used for the parameter x is shown on the
horizontal axis. The vertical axis will show the n2 values
of the sequence y(n1+1),..., y(n1+n2+1) obtained after letting
the sequence evolve n1 iterations. In addition to the options
accepted by plot2d, it accepts an option pixels that
sets up the maximum number of different points that will be represented
in the vertical direction.

Example. Orbits diagram of the quadratic map, with a parameter
a:

(%i1) orbits(x^2+a, 0, 50, 200, [a, -2, 0.25], [style, dots]);

To enlarge the region around the lower bifurcation near x = -1.25 use:

Draws a staircase diagram for the sequence defined by the recurrence
relation

y(n+1) = F(y(n))

The interpretation and allowed values of the input parameters is the
same as for the function evolution. A staircase diagram consists
of a plot of the function F(y), together with the line G(y)=y. A vertical segment is drawn from the point (y0,
y0) on that line until the point where it intersects the function
F. From that point a horizontal segment is drawn until it reaches
the point (y1, y1) on the line, and the procedure is
repeated n times until the point (yn, yn) is
reached. The options are the same as for plot2d.

54.3 Visualization with VTK

Function scene creates 3D images and animations using the Visualization
ToolKit (VTK) software. In order to use that function, Xmaxima and VTK should be
installed in your system (including the TCL bindings of VTK, which in
some system might come in a separate package).

Function:scene (objects, …, options, …);

Accepts an empty list or a list of several objects
and options. The program launches Xmaxima, which
opens an external window representing the given objects in a
3-dimensional space and applying the options given. Each object must
belong to one of the following 4 classes: sphere, cube, cylinder or cone
(see Scene objects). Objects are identified by
giving their name or by a list in which the first element is the class
name and the following elements are options for that object.

Example. A hexagonal pyramid with a blue background:

(%i1) scene(cone, [background,"#9980e5"])$

By holding down the left button of the mouse while it is moved on the
graphics window, the camera can be rotated showing different views of
the pyramid. The two plot options elevation and
azimuth can also be used to change the initial
orientation of the viewing camera. The camera can be moved by holding
the middle mouse button while moving it and holding the right-side mouse
button while moving it up or down will zoom in or out.

Each object option should be a list starting with the option name,
followed by its value. The list of allowed options can be found in the
Scene object's options section.

Example. This will show a sphere falling to the ground and
bouncing off without losing any energy. To start or pause the
animation, press the play/pause button.

The restart option was used to make the animation restart
automatically every time the last point in the position list is reached.
The accepted values for the colors are the same as for the color
option of plot2d.

54.3.1 Scene options

Scene option:azimuth [azimuth, angle]

Default value: 135

The rotation of the camera on the horizontal (x, y) plane. angle
must be a real number; an angle of 0 means that the camera points in the
direction of the y axis and the x axis will appear on the right.

The vertical rotation of the camera. The angle must be a real
number; an angle of 0 means that the camera points on the horizontal,
and the default angle of 30 means that the camera is pointing 30 degrees
down from the horizontal.

54.3.2 Scene objects

Scene object:cone [cone, options]

Creates a regular pyramid with height equal to 1 and a hexagonal base
with vertices 0.5 units away from the axis. Options
height and radius can be used
to change those defaults and option resolution
can be used to change the number of edges of the base; higher values
will make it look like a cone. By default, the axis will be along the x
axis, the middle point of the axis will be at the origin and the vertex
on the positive side of the x axis; use options
orientation and center to
change those defaults.

Example. This shows a pyramid that starts rotating around the z
axis when the play button is pressed.

A cube with edges of 1 unit and faces parallel to the xy, xz and yz
planes. The lengths of the three edges can be changed with options
xlength, ylength and
zlength, turning it into a rectangular box and
the faces can be rotated with option orientation.

Creates a regular prism with height equal to 1 and a hexagonal base with
vertices 0.5 units away from the axis. Options
height and radius can be
used to change those defaults and option resolution can be used to change the number of edges of the base;
higher values will make it look like a cylinder. The default height can
be changed with the option height. By default,
the axis will be along the x axis and the middle point of the axis will
be at the origin; use options orientation and
center to change those defaults.

54.3.3 Scene object's options

Object option:animation [animation, property, positions]

property should be one of the following 4 object's properties:
origin, scale,
position or
orientation and positions should be a
list of points. When the play button is pressed, the object property
will be changed sequentially through all the values in the list, at
intervals of time given by the option tstep. The
rewind button can be used to point at the start of the sequence making
the animation restart after the play button is pressed again.

The coordinates of the object's geometric center, with respect to its
position. point can be a list with 3
real numbers, or 3 real numbers separated by commas. In a cylinder, cone
or cube it will be at half its height and in a sphere at its center.

In a sphere phi is the angle on the vertical plane that passes through
the z axis, measured from the positive part of the z axis. angle
must be a number between 0 and 180 that sets the final value of phi at
which the surface will end. A value smaller than 180 will eliminate a
part of the sphere's surface.

In a sphere theta is the angle on the horizontal plane (longitude),
measured from the positive part of the x axis. angle must be a
number between 0 and 360 that sets the final value of theta at which the
surface will end. A value smaller than 360 will eliminate a part of
the sphere's surface.

Three angles by which the object will be rotated with respect to the
three axis. angles can be a list with 3 real numbers, or 3 real
numbers separated by commas. Example: [0, 0, 90] rotates
the x axis of the object to the y axis of the reference frame.

Three numbers by which the object will be scaled with respect to the
three axis. factors can be a list with 3 real numbers, or 3 real
numbers separated by commas. Example: [2, 0.5, 1]
enlarges the object to twice its size in the x direction, reduces the
dimensions in the y direction to half and leaves the z dimensions
unchanged.

In a sphere phi is the angle on the vertical plane that passes through
the z axis, measured from the positive part of the z axis. angle
must be a number between 0 and 180 that sets the initial value of phi at
which the surface will start. A value bigger than 0 will eliminate a
part of the sphere's surface.

In a sphere theta is the angle on the horizontal plane (longitude),
measured from the positive part of the x axis. angle must be a
number between 0 and 360 that sets the initial value of theta at which
the surface will start. A value bigger than 0 will eliminate a part of
the sphere's surface.

The surfaces of the object will be rendered and the lines and points of
the triangulation used to build the surface will not be shown. This is
the default behavior, which can be changed using either the option
points or wireframe.

positions should be a list of points. When the play button is
pressed, the object position will be changed sequentially through all
the points in the list, at intervals of time given by the option
tstep, leaving behind a track of the object's
trajectory. The rewind button can be used to point at the start of the
sequence making the animation restart after the play button is pressed
again.

Example. This will show the trajectory of a ball thrown with
speed of 5 m/s, at an angle of 45 degrees, when the air resistance can
be neglected: