\( \DeclareMathOperator{\abs}{abs} \newcommand{\ensuremath}[1]{\mbox{$#1$}} \)

Animation in wxMaxima: with_slider_draw

  Using the command with_slider_draw enables one to create animations within a wxMaxima session. The material below, developed by David A. Stegenga, is part of a set of material at http://www.math.hawaii.edu/home/wxmaxima.shtml. Additional examples of applications to two dimensional graphs are at  http://www.cs.us.es/~jalonso/cursos/i1m/temas/tema-CS7/tema_CS7.html.



The animation developed below is activated by using either the play button  (triangle) or the slider at its right on the toolbar. More instructions follow below. The animations occur within the wxMaxima session. For information regarding animation in draw, refer to http://www.telefonica.net/web2/biomates/maxima/gpdraw/animation.



This wxMaxima session contains two examples. The first uses wxdraw2d and  its animation-generating counterpart with_slider_draw. The second example  uses wxdraw3d and its counterpart with_slider_draw3d. The material developed here is exported to an html file, which is edited slightly with the open-source editor KompoZer (available at http://kompozer.net/).



The illustrations are developed using Version 0.8.7 of wxMaxima and Maxima version: 5.23.2 (build date: 11:22 2/2/2011) in a Windows XP environment and tested using Version 0.8.5 of wxMaxima and Maxima version 5.22.1 (build date 11/8/2010) in an Ubuntu environment.



Changelog:

(14.03.2019, eg, erklue@gmail.com): Changed the labelling of the graphics since it produced an error on wxmaxima 19.03.1 (on maxima 5.42.2). Removed the former "label" and used instead "key". Value of the area of the rectangle should now update during the animation.  

(15.03.2019 wxMaxima@physikbuch.de): Removed many of the hard linebreaks from the comments as wxMaxima now supports breaking lines automatically.

 1 Using with_slider_draw in wxdraw2d

  Example. The problem is to find the largest inscribed rectangle in a semicircle of radius 1.



Before using with_slider_draw to animate the graph, we look at a static graphical representation, using the draw graphics  package without animation, showing a typical such rectangle inscribed  under the curve y=f(x) where f(x)=(1-x^2)^(1/2).



The rectangle is determined by the its upper right vertex located  at the point (t,f(t)), where 0<t<1, and the area is given by (2t)f(t).  We first take t=.5 to see the picture. The function and the  relevant calculations appear in the table below.

--> kill(all)$ fpprintprec:5$   load(draw)$
set_draw_defaults(font="Tahoma", font_size=9);
f(x):= (1x^2)^(1/2)$   a: 0.5$ f(a)$ A:2·a·f(a)$
matrix(["f(x)","a","f(a)","A"],[f(x), a, f(a), A]);
\[\tag{%o3} [\mathit{font}=Tahoma,\mathit{font\_ size}=9]\] \[\tag{%o8} \begin{pmatrix}f(x) & a & f(a) & A\\ \sqrt{1-{{x}^{2}}} & 0.5 & 0.86603 & 0.86603\end{pmatrix}\]

  The draw command creates two labels. The first creates the text "Area =" and the second shows the value of the area. The explicit command creates the curve and the rectangle command creates the inscribed rectangle.

--> wxdraw2d(xrange = [1.5,1.5], yrange = [.5,1.5],
        xaxis = true, yaxis = true,
   key=concat("Area = ", float(%pi/2)),
        color = blue, explicit(f(x),x,1,1),
      key=concat("Area = ", float(2·a·f(a))),
        color = red, rectangle([a,0],[a,f(a)])            )$
\[\tag{%t9} \]  (Graphics)

  With this set of values we get an area of approximately 0.866. We next create an animation using the with_slider_draw( ) command with several values of  the counter t (other names can be assigned to the counter).

The command with_slider_draw replaces the command wxdraw2d( ). The first two entries inside the parentheses must be a counter and a list of  values. In most cases, the easiest way to create the list is by using the makelist command. In the case below, values of t ranging from 0 to 1 are created, with increments of 0.05.



After executing the set of commands in the cell below, click on the graph. The graph will be highlighted. At this point, clicking on the play button on the toolbar causes wxMaxima to scroll though the 21 values of t and project the results onto the screen. The animation continues until you click anywhere on the screen. Alternatively, clicking on the slider after highlighting the graph allows a more controled animation.

--> with_slider_draw(          t, makelist(.05·i,i,0,20),
        xrange = [1.5,1.5], yrange = [.5,1.5],
        xaxis = true, yaxis = true,
       key=concat("Area=", float(%pi/2)),
        color = blue, explicit((1x^2)^.5,x,1,1),
       key=concat("Area=", float(2·t·f(t))),
       color = red, rectangle([t,0],[t,f(t)])             )$
\[\tag{%t10} \] Animated Diagram

  A little experimenting suggests that the largest area is about 1 and the value of x that generates this area is around 0.7. The biggest rectangle is clearly not a square.



Of course, Maxima can be used to determine the value of x that yields maximum area. The series of commands below shows that the critical value of x is x/sqrt(2) (approximately 0.707), and that the resulting area is A(1/sqrt(2)) = 1.0.

--> A(x):= 2·x·f(x);
diff(A(x), x);
solve(%, x);
rhs(%[2]),numer;
A(%);
\[\tag{%o11} \operatorname{A}(x):=2 x \operatorname{f}(x)\] \[\tag{%o12} 2 \sqrt{1-{{x}^{2}}}-\frac{2 {{x}^{2}}}{\sqrt{1-{{x}^{2}}}}\] \[\tag{%o13} [x=-\frac{1}{\sqrt{2}},x=\frac{1}{\sqrt{2}}]\] \[\tag{%o14} 0.70711\] \[\tag{%o15} 1.0\]

  The graph below confirms that a maximum value is determined (as the animation has already demonstrated) and that only one such local maximum exists over the range considered.

--> wxdraw2d(xlabel = "x", ylabel = "A(x)", explicit(A(x),x,0,1))$
\[\tag{%t16} \]  (Graphics)

 2 Using with_slider_draw in wxdraw3d

  This section demonstrates that with_slider_draw in three dimensions works much the same as in two dimensions. We use a saddle-shaped surface and show how the animation can be applied. The function is z(x,y) = y^2-x^2.



Again, we start with a static graph.

The graph below shows the surface and three contour lines, those for z = -5, z = 0, and z = 5. The contour lines appear on the base of the graph and on the surface, which is the default setting. Below, we limit the graph to a pair of contour lines at a time, but the levels change.

--> kill(all)$ z(x, y):=y^2 x^2;
wxdraw3d(view=[55,120], xaxis=true, yaxis=true,
enhanced3d=true, contour = both,
ztics={9, 0, 9}, xlabel="x", ylabel="y",zlabel="z",
explicit(z(x, y),x, 3, 3, y, 3, 3)
)$
\[\tag{%o1} \operatorname{z}\left( x,y\right) :={{y}^{2}}-{{x}^{2}}\] \[\tag{%t2} \]  (Graphics)

  The command with_slider_draw3d replaces wxdraw3d and we add a counter, again named t. The contour levels are set at a given two values, t-1 and t+1.

--> with_slider_draw3d(t, makelist(0.2·i,i,10,10),
xaxis=true, yaxis=true,
enhanced3d=true, contour = both,
ztics={9, 0, 9}, xlabel="x", ylabel="y",zlabel="z",
contour_levels = {t1, t+1},
explicit(z(x, y),x, 3, 3, y, 3, 3)  )$
\[\tag{%t3} \] Animated Diagram

  The counter can be used to shift the surface itself, as below.

--> with_slider_draw3d(t, makelist(0.2·i,i,10,10),
xaxis=true, yaxis=true,
enhanced3d=true, contour = both,
ztics={9, 0, 9}, xlabel="x", ylabel="y",zlabel="z",
contour_levels = {t1, t+1},
explicit(z(t·x, y),x, 3, 3, y, 3, 3)   )$
\[\tag{%t4} \] Animated Diagram
Created with wxMaxima.