The Explore command - Maple Programming Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Applications and Example Worksheets : Mathematical Visualization : examples/Explore

The Explore command



The Explore command provides the functionality to quickly and easily construct and insert a collection of embedded components for exploring the results of commands or procedures which return expressions, plots, or images. The automatically constructed components are inserted inside a worksheet table and the exploration is accomplished by moving controllers such as slider components.


Details on all the options provided by the command are available on the Explore help page. This worksheet provides additional examples and commentary on the use of the command.


Tip: The inserted assembly of embedded components will be treated like output by the Graphical User Interface (GUI). Re-executing Explore commands will replace the previously inserted content. To retain the inserted collection of embedded components in a more permanent way, you can copy and paste the whole inserted GUI table which contains them. Once pasted in elsewhere they should function as before, even if the original Explore command that produced them is deleted.


Introduction and basic concepts


The essence of the exploration concept is that an expression may depend upon names which are considered as real-valued independent parameters. The Explore command constructs an interface in which a variety of results can be consecutively displayed as the values of the parameters change according to some interactive controllers. The interactive application which the Explore command inserts will dynamically substitute values for the parameters, evaluate, and display each result.


For example, the following plotting command call contains the name A , upon which it depends. If name does not have a numeric value then evaluation of that plotting command call would generate an empty plot.


plot3d( sin(A*y)*x^2, x = -1..1, y = -Pi..Pi );


The Explore command allows us to construct and interface in which the plot is recomputed with parameter A taking on various numeric values.


Parameters and initialvalues


The parameters optional argument of the Explore command allows you to specify which of the unknown names in an expression of plot are the parameters to be explore via sliders. In addition, the initialvalues option allows you to specify the parameter values to be used in the first evaluation.


Compare the following two examples:


In the first example, a pop-up dialog window will appear, suggesting end points for parameters A and B. Click on the Explore button to accept the suggested values.


The second example allows you to bypass the pop-up dialog altogether, by programmatically specifying the parameters' ranges and initial values.


Explore( plot3d( sin(A*y) * B * x^2, x = -1..1, y = -Pi..Pi, view = -2..2 ) );




Explore( plot3d( sin(A*y) * B * x^2, x = -1..1, y = -Pi..Pi, view = -2..2 ),
         parameters = [A = 0..10, B = 0.0..10.0], initialvalues=[A=3, B=4] );



Exploring a mathematical expression


Expressions or function calls which evaluate to other mathematical expressions, following substitution of parameter values, can also be explored.


The component displaying the resulting expressions is a Math Expression Component (or MathContainer).


Tip: Properties such as the autofit, border display, and dimensions of the MathContainer can be altered using the right-click context menu on that component.


With exploration of mathematical expressions it can be useful to see the unevaluated expression alongside each result.The following examples demonstrate several ways in which the result may or may not be displayed as an equation, including as an identity involving the unevaluated expression.



By default the result displays as an equation, with the unevaluated expression echoed as the left-hand-side.


Explore( factor(sum(i^n,i=1..N)), parameters=[n=1..10] );



Display of that left hand side can be optionally suppressed.


Explore( factor(sum(i^n,i=1..N)), parameters=[n=1..10], echoexpression=false );



Since an equation can also be explored, a customized identity could be shown instead. In this next example the left hand side of the input expression is within unevaluation quotes, so that the right hand side summation is computed symbolically while the left hand side is not.


Explore( 'sum'(i^n,i=1..N)=factor(sum(i^n,i=1..N)), parameters=[n=1..10], echoexpression=false );



Yet another variation on the above is to use the inert operator Sum rather than the active sum. Note the lighter shade of the pretty-printed summation symbol.


Explore( Sum(i^n,i=1..N)=factor(sum(i^n,i=1..N)), parameters=[n=1..10], echoexpression=false );


Exploring a function call


One powerful way to use the Explore command is to pass it an unevaluated function call to a previously defined procedure.

The key here is that the procedure must consistently return the kind of object to be explored, whether that be a plot, an expression, or an image.


At first glance the next example may appear trivial, but the technique is used in several of the more advanced application examples that come later in this worksheet.


f := proc(a) local b;
         b := a^2;
         return plot( sin(b*x), x=-2*Pi..2*Pi );
     end proc:

Explore( f(p), parameters=[p=-2.0 .. 2.0] );



Using previously assigned data


The following example illustrates the use of data which has previously been assigned to a name earlier in the session.


data := [[0,2],[1/2,1.5],[0.8,2.5],[1.4,2.6],[1.8,1.5],[2.2,3.1],[2.6,2.4],[3.1,2.2],[3.5,2.2]]:





Interactive plots

Interactive plots produced by the plots:-interactive command make use of new Explore functionality.


Issuing the following command will produce a pop-up dialog. When the pop-up dialog appears, select Interactive Plot with 1 parameter from the uppermost drop-down menu (combo-box) , then click Plot.


The result is comprised of Embedded Components inserted into the current worksheet.


plots:-interactive({cos(w), tan(w+z)}, variables=[w,z]);



Context-sensitive menus


The plots:-interactive functionality can also be accessed in a purely clickable manner, via the context-sensitive menus. Context-sensitive menus are used to apply operations to an expression using only the pointer. The menus are available for both 2-D Math output (following execution) and 2-D Math input (preceding execution).


Execute the first command below, then right-click (Control-click on Macintosh) on the output expression to bring up the associated context-sensitive menu. Select the Plots option from the pop-up menu. Inside the Plots submenu, select the Plot Builder. This should bring up the PlotBuilder window. Select Interactive Plot with 1 parameter in the uppermost drop-menu, then click on the Plot button to finish.


In a Worksheet this should insert another instance of the call to the Explore command and the embedded components. In a Document the embedded components will be displayed but the Explore call which created them will not be immediately visible.




Exploring an animation


The Explore command allows you to create an exploratory interface which can play frames as the instances of various parameter values. The frames are produced on-demand and kept only as they are needed. This contrasts with the animations produced by the animate plotting command, which must generate all frames in advance and retain them together. The frame on-demand approach to playing an exploration is discussed further on in this worksheet, but in this section we can see how the older style of animation is supported within an exploration interface.


After executing the Explore command below, select the plot with the pointer and run the animation using the top menu. By default, the embedded component will show the animation in continuous loop mode. While the animation is playing you can move the slider and see a changing instance of the animation.


Note that the animations are created on-the-fly for each new slider value.


Explore( plots:-animate( plot, [a+sin(b*x), x=-2*Pi..2*Pi, view=[-2*Pi..2*Pi,-5..5]], b=-2.0..2.0 ),
         parameters = [a=-3.0..3.0] );


Placement of controls

The controls for parameters can be placed either to the left, bottom, or right of the component displaying results. All parameter controls can be placed via a single optional argument to the Explore command, as a customized default.


Parameter controls can also be specified individually as an override of any default.

Explore( plot(b+abs((c-2)*(c+2))*cos(a*x),x=-6..6,view=-8..8),

         parameters=[ c=0.0..2,
                      [a=1..3.0, placement=bottom]





Control types for range parameters

Parameters whose values are specified as a range can have any of several types of variable controller.


The variable controller are: slider, dial, volumegauge, meter, and rotarygauge.


The size of the plotting component can be optionally specified. By default, its size is determined by the size of the initial plot.

Explore( plot(abs((c-2)*(c+2))*sin(a*x), x=-6..6, view=-4..4),

         parameters=[ [c=0.0..2, controller=volumegauge],
                      [a=1..3.0, controller=dial]




ComboBox controls

Parameters whose values are specified as lists are incorporated as Combo Box controls.

Explore( plot(abs((c-2)*(c+2))*sin(a*x), x=-6..6,
              view=-4..4, color=r, style=s),

         parameters=[ [r=[red,blue,green],label=color],






Advanced techniques


The display of the generated frames at each set of parameter values can be animated. Each parameter control can have its own check box which determines whether it will play with the animation. These check boxes can be unselected while the animation is playing.


Note that any parameters whose animation check box is unselected during play can still be interactively controlled.


The animation check boxes can be specified as a single new default option, and this in turn can be overridden on any parameter's individual specification.  The animation check boxes can be specified as present and initially selected, present and initially unselected, or absent altogether.


By default, any combo box control of a discrete valued parameter does not get an animation check box unless this is supplied in the parameter's individual specification.


Explore( plot(abs((c-2)*(c+2))*sin(a*x),x=-6..6,view=-4..4,color=r,style=s),

         parameters=[ [r=[red,blue,green],label=color,animate=true],





Loop Animation

The loop option allows for looped play of the animated sequence.


The loop control check box can be omitted altogether (default), initially selected, or initially unselected.

Explore( plot(abs((c-2)*(c+2))*sin(a*x),x=-6..6,view=-4..4,color=r,style=s),

         parameters=[ [r=[red,blue,green],label=color,animate=true],




Numerical Ordinary Differential Equations with parameters


Suppose that you have an Initial Value Problem (IVP) with unassigned symbolic parameters. The interactive functionality of dsolve,numeric provides an efficient mechanism for numerically solving the solution at multiple values of the parameters. You can use the Explore command to interact with such a solution space.


sol := dsolve( {alpha*diff(x(t),t)=0.7*(y(t)-x(t))-sin(x(t))^2,
                x(0)=3, y(0)=0, z(0)=-3},
                {x(t), y(t), z(t)},
                numeric, 'parameters'=[alpha,beta], 'output'='listprocedure'):

caller := proc(a,b); sol('parameters'=['alpha'=a,'beta'=b]); sol; end proc:

            plots:-odeplot( caller(A,B), [x(t), y(t), z(t)], t = 0 .. 500,
                            'style'=line, 'numpoints'=10000, 'labels'=[`x`,`y`,`z`],
         end proc:

You can now produce a plot of the solution at parameter values alpha=0.1 and beta=0.2.




And you can also explore the family of such plots, as the parameter values change. This is accomplished by calling Explore on a function call.


Explore( attract(a,b),
         'parameters'=[a=0.5..2.0, b=1.0..10.0] );




Procedures which return images can be explored interactively.

Basic example: float[8] Array


Arrays which are supported by the ImageTools package can be interpreted as images.


The following is a basic example involving a function call which evaluates to a 2-dimensional datatype=float[8] Array which is interpreted as a grayscale image.

Explore( Array(1..100,1..100,(i,j)->evalf(sin(p/10*(i+j))),datatype=float[8]),
         parameters=[p=2.0..4.0], size = [200, 200] );


Procedures returning an image


A function call to a command or procedure which returns an image can also be explored.

img := ImageTools:-Read(cat(kernelopts(datadir),"/images/excavator.jpg")):

Explore( ImageTools:-Threshold(img, threshold),
         parameters=[threshold=0.2..0.8], placement=right, size = [320, 210] );




Exploration of images can also be animated.


Explore( Mandelbrot(300, -1.78+(-1-1.5*I)/exp(zoom), -1.78+(2.2+1.5*I)/exp(zoom),
                    iterationlimit=a, output=layer1)
         , parameters=[ a=50..300, zoom=0.0..8.0 ]
         , animate
         , placement=left );




Interactive markers

Pairs of range controls (e.g. sliders) can be coupled as interactive marker controls on 2D plots.  Each marker is displayed as a cross in the plot, which may be dragged interactively using the mouse pointer.


By default the sliding controls associated with marker parameters are hidden. These controls can be collectively made to display with the showmarkercontrols option, or individually made to display or not with the optional shown keyword in the individual parameter's specification.

DEplot and initial conditions

deS := diff(x(t),t)=-0.5*x(t)*y(t);



deI := diff(y(t),t)=+0.5*x(t)*y(t)-0.15*y(t);



Explore( DEtools[DEplot]( [deS,deI], [x(t),y(t)],
                          t=0..40, x=0..1, y=0..0.6,
                          [[x(0)=x0,y(0)=y0]], arrows=medium),

         parameters=[ [x0=0.3..0.99], [y0=0.1..0.5, shown=false] ],


         placement=left, animate );







Signal Processing: Infinite Impulse Response Filter


The following application uses example code from the SignalProcessing package and, after enclosure in a simple procedure, produces an interactive application that dynamically illustrates the effects of the filter parameter value on the resulting modified signal.


First we generate a known signal. Then we construct a reusable container Array C in order to improve performance of the exploration process by leveraging the in-place computational semantics of the InfiniteImpulseResponseFilter command.


Jsignal:=SignalProcessing:-GenerateJaehne( 512, 4095 ):
PJsignal:=plots:-listplot( Jsignal, 'title' = "Original Signal" ):

  uses SignalProcessing;
  local PB,taps;
  PB:=plots:-listplot(Ctemp,'title'="Filtered Signal");
end proc:

        placement=left, animate, loop,
        title="Infinite Impulse Response Filter");

Infinite Impulse Response Filter




RGB color space: an application


The next example uses a self-initializing module to efficiently do in-place updates of an image Array as the parameters change.


   local ModuleApply,init,f,sr,sg,sb,n,n1,n2,c,tc,R;
      n:=200; n1,n2:=trunc(n/4),trunc(n/2);
   end proc;
   end proc;
      if not n::posint then init(); end if;
      if sr<>tr then
      end if;
      if sg<>tg then
      end if;
      if sb<>tb then
      end if;
   end proc;
end module:

A single call to F will produce a color image as output, which can be visualized by embedding in the current worksheet.

ImageTools:-Embed( RGBapp(0.7,0.3,0.9) );

An interactive application can now be easily constructed.


Explore( RGBapp( Red, Green, Blue ),

         parameters = [ Red=0.2..1, Green=0.2..1, Blue=0.2..1],
         initialvalues = [ Red=.7, Green=.7, Blue=.7 ],
         placement = right,

         title="The additive RGB color space" );

The additive RGB color space




Cobweb plot of the logistic map


The cobweb plot of the logistic map illustrated by iterated application of the formula r*x*(1-x) exhibits emergent chaotic behaviour as the parameter r increases from a value of 3 towards the value of 4.


Cobweb:=proc(r, x0, {numpoints::posint:=1})

     local f,i,M,N,x;






     for i from 3 to N-1 by 2 do



     end do;





end proc:


The procedure Cobweb defined below will produce a so-called cobweb plot by iterating the process of applying the formula to obtain a y value and taking that computed y value as the next x value in the sequence. This sequence of operations produces (x,y) points which lie alternately on the formula's curve and the x=y line.


Cobweb( 2.8, 0.1, numpoints=10 );


For some values of r convergence to a point or a cycle occurs. As the value r increases towards 4 the chaotic behaviour emerges. A dynamic exploratory interface with varying parameters r and x0 are much more impressive mechanisms for illustrating the emergent behavior than are static cobweb plots with fixed values of r and original point x0.


Explore( Cobweb( r, x0, numpoints=n ),
         parameters=[ r=2.0 .. 4.1,
                      [x0=0.0 .. 1.0, animate=false],
                      [n=1 .. 200, animate=false] ],
         initialvalues=[r=2.8, x0=0.1, n=100],
         animate, loop,
         title="Cobweb plot for r*x*(x-1)" );

Cobweb plot for r*x*(x-1)




Edge detection


The following application performs edge detection by convolving the data with a pair of 3x3 kernels (Sobel operator), followed by optional thresholding.


The discrete valued action parameter is used to allow the choice between convolution (only) or thresholding (only) after the initial convolution. When the action ComboBox is selected as threshold then the three Sliders control the thresholding effect on the displayed image. When the ComboBox is selected as convolve then the image reverts to the result of the original convolution and the three Sliders have no effect.


img := ImageTools:-Read(cat(kernelopts(datadir),"/images/undercarriage.jpg")):

GetEdges:=module() local Sobelx,Sobely,ModuleApply,edge,stored;
  Sobelx := Matrix([[1,2,1],[0,0,0],[-1,-2,-1]],':-datatype'=':-float[8]'):
  Sobely := Matrix([[-1,0,1],[-2,0,2],[-1,0,1]],':-datatype'=':-float[8]'):
    local g_img,img_x,img_y,min_v,max_v;
    uses ImageTools;
    if action=':-convolve' then
      g_img := ToGrayscale(img):
      img_x,img_y := Convolution(g_img,Sobelx),Convolution(g_img,Sobely);
      edge := img_x+img_y;
      FitIntensity(edge, ':-inplace'=true);
      return edge;
    elif action=':-threshold' then
      if type(edge,Image) then
        return Threshold(edge,t,':-high'=high,':-low'=low );
      else error "action convolve must precede action threshold"; end if;
      return img;
    end if;
  end proc:
end module:

Explore( GetEdges(img,action=act,t=thresh,high=highval,low=lowval),
         placement=right, size=[400,267],
         title="Edge detection by convolution and thresholding" );

Edge detection by convolution and thresholding




Return to Index for Example Worksheets

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam