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 by using interactive graphing tools. Load the parserGraphTool.pl macro for this.

$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

Two intervals are created with random enpoints. The first one is a bounded interval, and the second an unbounded 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. The remaining attributes depend on the type of graph object. For an interval, there is only one attribute which is 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: For a number line the bounding box is an array reference [xmin, xmax] containing the left and right limits of the visible graph.
  • availableTools: This determines which tools will be available for the student to use.
  • ticksDistanceX: The distance between tick marks in the x direction.
  • minorTicksX: The number of minor ticks to show. This can be 0.
  • 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.