Interactive graphing tool problem that asks the student to plot a line.
Download file: GraphToolLine.pg
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 line) by using interactive graphing tools. Load the parserGraphTool.pl macro for this.
$x0 = non_zero_random(-6, 6); $y0 = non_zero_random(-6, 6); $line = nicestring([ $y0, $x0 ], [ 'x', 'y' ]); $gt = GraphTool("{line, solid, ($x0, 0), (0, $y0)}")->with( bBox => [ -11, 11, 11, -11 ], availableTools => [ 'PointTool', 'LineTool', 'CircleTool', 'QuadraticTool', 'CubicTool', 'FillTool', 'SolidDashTool' ], );
Setup
A cubic is created with 3 random zeros and a random y-intercept.
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, line
in this case. What the remaining attributes are depend on the type. For a line the second attribute is whether the object is to be solid
or dashed
, and the remaining attibutes are two distinct points on the line.
The ->with
method is then used to set options for the GraphTool
object. In this case the options that are set are:
bBox
: This is an array reference of four values xmin, ymax, xmax, ymin indicating the upper left and lower right corners of the visible graph.availableTools
: This determines which tools will be available for the student to use.There is a default checker for the GraphTool that will mark correct a student answer that ‘looks’ like the correct one. For simple graphs, the default should be sufficient. See Graph Tool, custom checker for an example of how to use a custom checker.
BEGIN_PGML On the graph below, plot the line [`[$line] = [$x0*$y0]`] [_]{$gt} END_PGML
Statement.
The code [_]{$gt}
inserts the GraphTool.
BEGIN_PGML_SOLUTION Two points are needed off this line. It could be put in slope-intercept form which would give a [`y`]-intercept and then a second point could be determined from the slope. Alternatively, the intercept form on the line is found by dividing the equation by the right hand side to [```\frac{x}{[$x0]}+ \frac{y}{[$y0]}=1```] and thus the [`x`]-intercept is number in the fraction under the [`x`] or [$x0] and the [`y`]-intercept is the number in the fraction under the [`y`] or [$y0]. The solution is [@ $gt->generateAnswerGraph @]* END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.