Difference between revisions of "GraphTool"
Jump to navigation
Jump to search
(Correct typo) |
(added historical tag and gave updated problem link) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with many other problems:</p> |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolCircle.html A graph tool with circle] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolCubic.html A graph tool with cubic] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolLine.html A graph tool with line] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolNumberLine.html A graph tool with a number line] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolCustomChecker.html A graph tool with custom checker] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/GraphToolPoints.html A graph tool with points] |
||
+ | |||
<h2>Graph Tool</h2> |
<h2>Graph Tool</h2> |
||
Line 46: | Line 56: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | + | # Define the answer checker for the graph tool. |
|
− | + | # This checker allows the student to graph the correct circle multiple |
|
− | # This grader allows the student to graph the correct circle multiple |
||
# times. The idea is that the graph is graded based on appearance. |
# times. The idea is that the graph is graded based on appearance. |
||
# No matter how many times the student graphs the correct circle, |
# No matter how many times the student graphs the correct circle, |
||
Line 78: | Line 88: | ||
my $nth = Value::List->NameForNumber($count++); |
my $nth = Value::List->NameForNumber($count++); |
||
− | # |
+ | # This checks if the student input matches the circle, type |
# (solid or dashed), the center of the circle and |
# (solid or dashed), the center of the circle and |
||
# checks if a point is on the circle. |
# checks if a point is on the circle. |
||
Line 88: | Line 98: | ||
$pointOnCircle->($_->extract(4))); |
$pointOnCircle->($_->extract(4))); |
||
− | # |
+ | # The following gives additional information to the student. |
push(@errors, "The $nth object graphed is not a circle"), |
push(@errors, "The $nth object graphed is not a circle"), |
||
Line 110: | Line 120: | ||
Context()->variables->add("y" => "Real"); |
Context()->variables->add("y" => "Real"); |
||
$circle_eq_lhs = Formula("(x-$h)^2 + (y-$k)^2")->reduce; |
$circle_eq_lhs = Formula("(x-$h)^2 + (y-$k)^2")->reduce; |
||
− | |||
− | |||
$gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with( |
$gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with( |
||
Line 140: | Line 148: | ||
<li>Other parameters of the <tt>GraphTool</tt> can be set using <tt>with</tt>. The following include other features: |
<li>Other parameters of the <tt>GraphTool</tt> can be set using <tt>with</tt>. The following include other features: |
||
<ul> |
<ul> |
||
− | <li><tt>bbox</tt>: this is an array reference of four values <tt>xmin, |
+ | <li><tt>bbox</tt>: this is an array reference of four values <tt>xmin, ymax, xmax, ymin</tt> indicating the upper left and lower right corners of the visible graph.</li> |
<li><tt>cmpOptions</tt>: this is a hash of options passed to the <tt>cmp</tt> method for checking the answer. The example here: |
<li><tt>cmpOptions</tt>: this is a hash of options passed to the <tt>cmp</tt> method for checking the answer. The example here: |
||
<pre> |
<pre> |
Latest revision as of 10:11, 29 June 2023
This problem has been replaced with many other problems:
- A graph tool with circle
- A graph tool with cubic
- A graph tool with line
- A graph tool with a number line
- A graph tool with custom checker
- A graph tool with points
Graph Tool
This example shows how to get student input in the form of a graph (a circle) by using interactive graphing tools.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGML.pl", "parserGraphTool.pl" ); TEXT(beginproblem()); |
Initialization: It is important to include the parseGraphTool.pl macro. |
# Define the answer checker for the graph tool. # This checker allows the student to graph the correct circle multiple # times. The idea is that the graph is graded based on appearance. # No matter how many times the student graphs the correct circle, # the resulting graph appears the same. $gt_checker = sub { my ($correct, $student, $ans, $value) = @_; return 0 if $ans->{isPreview}; my $score = 0; my @errors; my $count = 1; # Get the center and point that define the correct circle and # compute the square of the radius. my ($cx, $cy) = $correct->[0]->extract(3)->value; my ($px, $py) = $correct->[0]->extract(4)->value; my $r_squared = ($cx - $px) ** 2 + ($cy - $py) ** 2; my $pointOnCircle = sub { my $point = shift; my ($x, $y) = $point->value; return ($x - $cx) ** 2 + ($y - $cy) ** 2 == $r_squared; }; # Iterate through the objects the student graphed and check to # see if each is the correct circle. for (@$student) { my $nth = Value::List->NameForNumber($count++); # This checks if the student input matches the circle, type # (solid or dashed), the center of the circle and # checks if a point is on the circle. $score += 1, next if ($_->extract(1) eq $correct->[0]->extract(1) && $_->extract(2) eq $correct->[0]->extract(2) && $_->extract(3) == $correct->[0]->extract(3) && $pointOnCircle->($_->extract(4))); # The following gives additional information to the student. push(@errors, "The $nth object graphed is not a circle"), next if ($_->extract(1) ne $correct->[0]->extract(1)); push(@errors, "The $nth object graphed should be a " . $correct->[0]->extract(2) . " circle."), next if ($_->extract(2) ne $correct->[0]->extract(2)); push(@errors, "The $nth object graphed is incorrect."); } return ($score, @errors); }; $h = non_zero_random(-5, 5); $k = non_zero_random(-5, 5); $r = random(1, 4); Context()->variables->add("y" => "Real"); $circle_eq_lhs = Formula("(x-$h)^2 + (y-$k)^2")->reduce; $gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with( bBox => [-11, 11, 11, -11], cmpOptions => { list_checker => $gt_checker } ); |
Setup:
|
BEGIN_PGML Graph the circle given by the following equation. [`[$circle_eq_lhs] = [$r ** 2]`] [_]{$gt} END_PGML |
Main Text: This asks to graph the circle given by the equation. And the code: [_]{$gt} inserts the GraphTool. |
BEGIN_PGML_SOLUTION The equation of the circle of the form: [`[$circle_eq_lhs] = [$r ** 2]`] has a center at [`([$h],[$k])`] and radius [$r]. To enter the graph, click the circle tool, then click the center at [`([$h],[$k])`] and then click a second point that is [$r] units from the center. This is easist going left, right, up or down from the center. END_PGML_SOLUTION ENDDOCUMENT(); |
This is the solution. |
- POD documentation: [2]