6.8 Plotting Using Maple - Maple T.A. 2016 Help
Maple T.A. Online Help

Instructor
Search Maple T.A. 2016 Help:

6.8 Plotting Using Maple

You can use Maple plotting features to display plots. Maple provides many ways of representing data and mathematical expressions graphically using plots. You can display a plot with any question type.

  • Displaying a Maple Plot with the plotmaple Command - Use the plotmaple command anywhere an algorithmic variable can be used, that is, in question text, hints, feedback, solution, and answer. For more information, see Displaying a Maple Plot.
  • Plotting a Student Response - Use Maple plotting features to graph student responses or a function derived from a student response. For more information, see Plotting a Student Response.
  • Plotting Options for 2-D and 3-D Maple Plots - Many options are available when generating a 2-D or 3-D Maple plot. For more information, see Setting Plot Options.

Displaying a Maple Plot

To display a plot within a question, use the plotmaple command:

  1. From the Question Editor screen, expand the Algorithm section.
  1. Enter the plotmaple algorithmic variable using the structure
$algorithmic_variable_name=plotmaple("plotstatement, libname='filename.lib', plotdevice='gif|jpeg', plotoptions='options'");
  1. Click Refresh algorithm preview to preview the plot image. See Figure 6.4.
  1. In the text field for the question type, enter the text of the question, including the algorithmic variable name defined in step 2.

Note: The algorithmic variable can also be used in the feedback or hints section.

Using plot options, you can specify the height and width of the image without losing any quality in the image. For example,

$myplot=plotmaple("plot(sin(x),x=-Pi..Pi), plotdevice='gif', plotoptions='height=250, width=250'");

You can use another algorithmic variable in the plot command. For example,

$a=range(1,5);
$myplot=plotmaple("plot($a*sin(x),x=-Pi..Pi), plotoptions='height=250, width=250'");

With the plotmaple command, you can specify whether you want the image saved as a GIF or JPEG. Maple animations are animated GIFs, so you must use GIF for an animation. For example,

$myanimation=plotmaple("plots[animate](sin(a*x),x=-Pi..Pi,a=1..4), plotdevice='gif'");

Note: You must use the long form name for Maple package functions

You can see a plot immediately using the Algorithm Editor.

Plot with Algorithmic Variables

Figure 6.4: Plot with Algorithmic Variables


Example Using a Label on a Plot

Labels can be added to Maple plots using the same method as adding labels to graphics. For detailed infomation on adding labels, see Questions with Labeled Images.

Enter the following in the Algorithm field:

$wave=plotmaple("plot(sin(x),x=0..10),plotoptions='height=130, width=200'")

In the Question Text section, click Source (). Include the following code:

<div class="labelledImage" style="height: 130px; width: 200px; float: none;">
$wave
<div style="left: 70px; top: 20px" class="centered">crest</div>
<div style="left: 120px; top: 120px" class="centered">trough</div>
</div>

The resulting plot is shown in Figure 6.5.

Plot with Labels

Figure 6.5: Plot with Labels


Example Using an Essay Question Type

The following is the source file for an Essay question type that displays a plot.


mode=Essay@
editing=useHTML@
algorithm=$wave=plotmaple("plot(sin(x),x=0..10)");@
question=Discuss the following wave.<br />
$wave@
 

Example Using a Randomly Generated Variable

The following is the source file for a Maple-graded Formula question type that displays a plot.


question=Determine the expression in the following plot.<br  />
$graph@
maple=evalb(($ANSWER)-($RESPONSE)=0);@
maple_answer=x^$n@
type=formula@
mode=Maple@
name=Displaying a Plot@
editing=useHTML@
algorithm=$n=maple("randomize():rand(1..10)()");
$graph=plotmaple("plot(x^$n,x=-2..2)");@

Example Using the Maple Tubeplot Command

The following is the source file for a True/False question type that displays a tube plot.

mode=True False@
name=tube plot@
editing=useHTML@
algorithm=$algorithmic_variable_name=plotmaple("plots[tubeplot](  [t*cos(3*Pi*t), t*sin(3*Pi*t), t], t=0..4, radius=.05, numpoints=70)");@
question=<p class="Listing">This displays a tube plot using the Maple long form name for the plots package.</p>
<p>$algorithmic_variable_name</p>@
answer=1@
choice.1=True@
choice.2=False@
fixed=@
 

Important: You must test your plot code prior to publishing assignments. Maple T.A. does not display error messages if the plot does not work correctly.

The drawMaplePlot command

Important: The Maple drawMaplePlot command has been superseded by the plotmaple command. Questions created using the drawMaplePlot command will continue to function. However, it is recommended that you use the plotmaple command.

To display a plot with a question using the drawMaplePlot command:

  1. From the Question Editor/Select Name and Type screen, select the Use HTML formatting for the question text option.
  1. Click Next.
  1. In the text field for the particular question type, click the Source button and enter the HTML script tags and structure illustrated below.

<script>drawMaplePlot("maplecode",width,height,"libname");</script>

<script>drawMaplePlot("plot(sin(x), x=0..10)",400,400);</script>

The script requires the following syntax:

  • <script> and </script> tags
  • drawMaplePlot command
  • Expression enclosed parentheses
  • Maple code to create plot, enclosed in quotes
  • Closing semicolon
  • width (optional) - specifies plot width
  • height (optional) - specifies plot height
  • libname (optional) - specifies path to Maple libraries

To use multiple libraries, place all libraries in the same directory and specify the path using the libname option.