Graph Tool, number line

Interactive graphing tool problem that asks the student to plot a circle.

Complete Code

Download file: GraphToolNumberLine.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl',
  'PGcourse.pl');

Preamble

This example shows how to get student input in the form of a graph (a circle) by using interactive graphing tools. Load the parserGraphTool.pl macro for this.

#  * availableTools: this determines which tools should be shown on the
$x1 = random(1, 5);

$gt1 = GraphTool("{interval,(-$x1,$x1]}")->with(
    availableTools => [ 'PointTool', 'IntervalTool', 'IncludeExcludePointTool' ],
    numberLine     => 1,
    bBox           => [ -6, 6 ],
    ticksDistanceX => 1,
    minorTicksX    => 0,
    useBracketEnds => 1
);

$x2 = random(-5,5);

$gt2 = GraphTool("{interval,(-inf,$x2)}")->with(
    availableTools => [ 'PointTool', 'IntervalTool', 'IncludeExcludePointTool' ],
    numberLine     => 1,
    bBox           => [ -6, 6 ],
    ticksDistanceX => 1,
    minorTicksX    => 0,
    useBracketEnds => 0
);

Setup

There are two different intervals created with random enpoints. The first one is finite, the second an infinite interval.

The GraphTool method creates the graph tool object. The only argument is the correct answer. This is a string that contains a list of objects that the student will be expected to graph. Each object is a brace delimited list of the attributes of the object. The first attribute in each list is the type of object to be graphed, interval in this case. What the remaining attributes are depend on the type and for this case, enter the interval in standard interval notation.

The ->with method is then used to set options for the GraphTool object. In this case the options that are set are:

  • numberLine is set to 1 (true) to indicate this is a one-dimensional graph.
  • bbox: since we are using an number the bounding box is just an array reference [xmin, xmax] graph tool. ticksDistanceX: indicates the distance between tick marks in the x direction minorTicksX: indicates the distance of subticks. The value 0 means no subticks.
  • useBracketEnds: 1 (true) means to use () and [] to denote the intervals a value of 0 means to use open and solid circles.
BEGIN_PGML
Graph the solution set for the linear inequality [`-[$x1] < x \leq [$x1]`].

[_]{$gt1}

Graph the solution set for the linear inequality [`x < [$x2]`].

[_]{$gt2}
END_PGML


ENDDOCUMENT();

Statement.

The code [_]{$gt} inserts the GraphTool.