Part 9: Dynamic Applications
Go to Maple Portal Previous Tutorial Next Tutorial
|
Introduction
|
|
Maple's Tutorials are designed to help you get started with Maple, learn about the key tools available in Maple, and lead you through a series of problems.
In Part 9: Dynamic Applications, you will learn to use interactive embedded components to create your own application. The first example in this tutorial demonstrates Maple's Exploration Assistant. This assistant lets you quickly create interactive mini-applications and explore the parameters of Maple expressions.
The second interactive example demonstrates how to use a simple set of components to plot a math expression. The third example shows how to create an interactive plot component which will allow a user draw circles by clicking on a point to define the center and clicking on another point that will be on the circle.
To try this material on your own, start with an empty Maple document. Perform the steps described in the left column of each table below. The results of the steps are displayed in the right column for reference.
Refer to Help>Quick Reference for basic getting started tips.
Note for non-Windows users: The keystrokes given in this document are for Windows. There will be differences for other platforms. If you are using a different platform, see Help>Quick Help for the list of the most common keystrokes.
|
|
Exploration Assistant
|
|
The Exploration Assistant allows you to instantly create interactive mini-applications which can be used to explore the parameters of any arbitrary Maple expression, such as a plot, mathematical equation or command. With these applications, you can use sliders to change the values of the parameters and see instant results.
There are two ways you can use the Exploration Assistant:
•
|
Right-clicking and selecting Explore from the context-sensitive menu
|
•
|
Calling the Explore command
|
Steps (Using the Context Menu)
|
Results
|
1. Enter the expression .
|
|
2. Right-click on the expression and select Explore.
|
|
A new dialog box will appear. From here, you can set the range of values you would like to explore, as well as select which variables you would like to skip. When you select skip, that parameter remains as a symbolic unknown in the expression; no slider will be created to control that value.
3. For a and b, enter -5 for the lower value and 5 for the upper value. Next to the variable x check the skip box on the right. This will leave the variable x unchanged in the expression. When you are finished, press Explore.
|
|
4. The Exploration Assistant opens in a new document with the expression and sliders for the indeterminates a and b. Move the sliders back and forth to see how they change the solution.
|
|
|
|
You can just as easily call the Exploration Assistant by using the Explore command, which takes as its parameter the Maple expression to be explored.
Steps (Using Commands)
|
Results
|
1. Enter the expression
and press [Enter].
|
|
2. In the dialog that appears, enter 1 for the lower ranges of a and b. When you are finished, press Explore.
|
|
3. The Exploration Assistant opens in a new document with a plot area and sliders for a and b. Move the sliders back and forth to see their effects on the plot.
|
|
|
|
For more information, see Using the Exploration Assistant.
|
|
Creating Basic Interactive Components
|
|
Embedded components can be added to a document from the Components palette. In this tutorial, we use the Plot Component and the Button Component.
Steps
|
Results
|
1. From the Components palette, add these components to your document:
•
|
Plot component
|
•
|
Mathematical expression component
|
•
|
Button component
|
|
|
2. Right-click on the plot
component and select Component Properties. This will bring up the Plot Properties window.
3. Change the Name to "MathPlot".
4. Click OK.
|
|
5. Right click on the mathematical expression
component, and select Component > Component Properties.
6. Change the Name to "PlotInput", and change the Height to 60.
7. Click OK.
|
|
8. Right click on the Button
component, and select Component Properties..
9. Change the Caption to "Plot Expression".
|
|
10. Within the same properties window, click on the Edit... button.
11. Copy and paste the code below into the space, after the use DocumentTools in line, but before the end use; line.
Do(%MathPlot=plot(%PlotInput,x=0..10));
Tip: You can clear all lines that start with # in the code region. The # denotes a comment and the line will not be executed. You must leave use DocumentTools in and end use; in order for the code to execute properly.
This line of code will create a plot from the mathematical expression entered in the input box and draw this plot in the MathPlot component.
12. Click OK, then click OK once more to return to your worksheet.
|
|
13. In the Mathematical Expression
component, enter a mathematical expression such as .
14. Click on the Plot Expression button.
|
|
|
|
For more information on the command used in the code to connect the embedded components, see DocumentTools[Do].
|
|
Building an Interactive Plot Component
|
|
Within a plot component, you can define click-and-drag behavior. You can enter commands to define actions to be performed in three scenarios:
•
|
Action When Clicked performs an action when the mouse is clicked in the plot area
|
•
|
Action When Dragged performs an action when the mouse is dragged in the plot area
|
•
|
Action When Drag Ends performs an action when the mouse is released from dragging.
|
To interact with the plot you need to use the Click and Drag manipulator
. This allows you to add or drag points on the plot area. You can access this manipulator from the Plot Toolbar or by right-clicking on the plot area and selecting Manipulators > Click and Drag.
For this example, you will be creating an interactive plot of a circle. First, you will click on a point to define its center, then define its radius by clicking on a point that will be on the circle. To set up this interactive plot, you will edit the Action When Clicked section of the plot component.
Steps
|
Results
|
1. From the Components Palette, click on the Plot
and Button
components to add them to your document.
|
|
Editing the Plot Properties
2. Right-click on the plot component and select Component Properties. This will bring up the Plot Properties window.
3. Change the Name to ClickPlot.
4. Select Make "execute code" the default manipulator. This will automatically execute the code the first time you click on the plot area.
5. Next to Action When Clicked, press the Edit button.
Tip: You can resize the area of the plot component by editing the Width and Height dimensions.
|
|
6. Insert the following commands above the end use; statement:
if type(CenX,symbol) then
You may delete all the comment lines (the lines beginning with #).
Tip: clickx and clicky store the coordinates of the position where the mouse click occurs. The command Do(%ClickPlot=...) references the plot component ClickPlot its values.
7. Press OK to accept the code, and press OK on the Plot Properties window.
|
|
Editing the Button Properties
8. Right-click on the button and select Component Properties. This will bring up the Button Properties window.
9. In the Caption area, type "Clear Plot". This will now be displayed on the button.
10. Next to Action When Clicked, press the Edit button. Insert the following commands above the end use; statement:
Do(%ClickPlot = plots:-pointplot([NULL]));
These commands clear the plot area.
11. Press OK to accept the code, and press OK on the Button Properties window.
|
|
Now the embedded component is ready to be tested. To use this mini-application:
•
|
Press Clear Plot to clear the component memory.
|
•
|
Click on the plot area and select the
icon from the Plot toolbar. This is the Click and Drag manipulator that will allow you to interact with the plot area.
|
Tip: You can access all plot manipulator tools from the Plot Toolbar, or by right clicking on the plot area and going to Manipulators.
•
|
Click on the plot area to chose the location of the center.
|
•
|
Click on a new location to chose a point on the circle. A circle is drawn.
|
You can clear the plot by pushing the Clear Plot button.
|
|
Here is a complete working plot component for you to try. Use the steps above to draw a circle.
|
|
|
|
For more information on the commands used in the code of this example, see DocumentTools[Do], plots[pointplot], and plottools[circle].
|
|
More Examples
|
|
For the remaining examples, you can view the code by right-clicking on the components and selecting Component > Component Properties, and clicking Edit on the various code regions. If you would like to re-create these examples, simply add the components in the same manner as the first example.
|
Line of Best Fit
|
|
In this example, as points are drawn on the plot, the line of best fit is updated and the equation of the line will be generated in the Math Expression area.
•
|
Press Clear Plot to clear the component memory.
|
•
|
Click on the plot area and select the
icon from the plotting toolbar.
|
•
|
Click on the plot area to add data points. The line of best fit will automatically be updated and its equation shown.
|
•
|
You can clear the plot by pushing the Clear Plot button.
|
To create this on your own, insert the
,
, and
components in your document using the Components Palette and copy the code from the example above.
Tip: The code in each component will refer to other components by name. Make sure the names match the names of your components.
|
|
Curve Fitting
|
|
Draw points on the plot, and a curve is drawn that interpolates the points using polynomial interpolation. This example uses a code edit region and a plot component. A code edit region provides a environment for writing code that does not appear in the main document. The code edit region icon also acts as a button. By clicking on the icon, the code inside that region is executed.
•
|
Click on the code edit region
button below.
|
•
|
Click on the plot area and select the
icon from the plotting toolbar.
|
•
|
You can now click on the plot area to add points and have Maple create a curve from your points. You can also take an existing point and drag it to a new location, and the curve will automatically update.
|
•
|
To clear the plot, press the
button again.
|
Click Here to Initialize Plot Region
To create this on your own, insert a Code Edit Region by going to go to Insert > Code Edit Region. You can right-click on the region to expand and collapse the area.
Using the Components palette on the left-hand side, click on the
component to add it to your document and copy the code from the example above.
|
These examples use the Least Squares and Polynomial Interpolation commands from the Curve Fitting package. For an introduction to Curve Fitting in Maple, see the Curve Fitting topic in the Maple Portal.
|
Go to Maple Portal Previous Tutorial Next Tutorial
|