Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sample problems and updates #1201

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserAssignment.pl', 'PGcourse.pl');
#:% section = setup
#: To allow assignments in the current context call `parser::Assignment->Allow`.
#: To allow students to enter an assignment in which the left side is a function
#: declaration call `parser::Assignment->Function('f')`. For more details, see
#: use `parser::Assignment->Function('f')`. For more details, see
#: PODLINK('parserAssignment.pl').
Context()->variables->are(x => 'Real', y => 'Real');
parser::Assignment->Allow;
Expand Down
4 changes: 2 additions & 2 deletions tutorial/sample-problems/Algebra/GraphToolCircle.pg
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#:% name = Graph Tool, plotting a circle
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% subject = [algebra, precalculus, geometry]
#:% categories = [graph, graphtool]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a circle)
Expand Down
2 changes: 1 addition & 1 deletion tutorial/sample-problems/Algebra/GraphToolCubic.pg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#:% name = Graph Tool, plotting a cubic
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% categories = [graph, graphtool]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a cubic)
Expand Down
2 changes: 1 addition & 1 deletion tutorial/sample-problems/Algebra/GraphToolCustomChecker.pg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#:% name = Graph Tool, custom checker
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% categories = [graph, graphtool]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a circle)
Expand Down
4 changes: 2 additions & 2 deletions tutorial/sample-problems/Algebra/GraphToolLine.pg
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#:% name = Graph Tool, plotting a line
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% subject = [algebra, precalculus, geometry]
#:% categories = [graph, graphtool]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a line)
Expand Down
6 changes: 3 additions & 3 deletions tutorial/sample-problems/Algebra/GraphToolNumberLine.pg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#:% name = Graph Tool, number line
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% categories = [graph, graphtool]

#:% section = preamble
#: This example shows how to get student input in the form of a graph
Expand All @@ -40,8 +40,8 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
#:
#: * `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.
#: * `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.
Expand Down
2 changes: 1 addition & 1 deletion tutorial/sample-problems/Algebra/GraphToolPoints.pg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#:% name = Graph Tool, plotting points
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]
#:% categories = [graph, graphtool]
#:% see_also = [GraphToolCircle.pg, GraphToolCubic.pg, GraphToolLine.pg, GraphToolNumberLine.pg]

#:% section = preamble
Expand Down
87 changes: 87 additions & 0 deletions tutorial/sample-problems/Arithmetic/UnitConversion.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## DESCRIPTION
## Answer is a number or formula with units
## ENDDESCRIPTION

## DBsubject(WeBWorK)
## DBchapter(WeBWorK tutorial)
## DBsection(PGML tutorial 2015)
## Date(02/15/2025)
## Institution(Fitchburg State University)
## Author(Peter Staab)
## Static(1)
## MO(1)
## KEYWORDS('differential calculus', 'units')

# Update 2025.02 to use the contextUnits.pl macro.

#:% name = Unit Conversion
#:% type = Sample
#:% subject = arithmetic
#:% categories = [units]

#:% section = preamble
#: We load `contextUnits.pl` in order to use the Units context.
DOCUMENT();

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

#:% section = setup
#: The Units context is from the PODLINK('contextUnits.pl') macro.
#: This is related to the 'Numeric' context with the ability to handle units.
#: The first question involves volume units so we set that.
#:
#: The `->toUnits` method converts the given number with units to the
#: requested unit.
#:
#: The second part below is a different conversion question, so the line
#: `Context('Units')->withUnitsFor('length', 'time');` resets the contxt with
#: a new set of units.
Context('Units')->withUnitsFor('volume');

$v = random(25, 200, 25);
$vol = Compute("$v ml");
$vol_cups = $vol->toUnits('cup');

Context('Units')->withUnitsFor('length', 'time');

$s = random(22, 110, 11);
$speed = Compute("$s ft/s");
$speed_mph = $speed->toUnits('mi/h');

#:% section = statement
#: The `with(sameUnits =>1)` requires the student answer to be in the same
#: units. Use `helpLink('units')` for students to have access to the complete
#: list of units that WeBWorK understands.
BEGIN_PGML
Perform the following unit conversions:

a) Convert [$vol] to cups. You may use [`1\;\text{l} = 1000\;\text{ml}`],
[`1\;\text{qt} = 0.9464\;\text{l}`] and [`1\;\text{qt}=4\;\text{cups}`].

Answer: [_]{$vol_cups->with(sameUnits => 1)}

b) Convert [$speed] to miles per hour. Recall that
[`1\;\text{mile}=5280\;\text{feet}`].

Answer: [_]{$speed_mph->with(sameUnits => 1)}

Note: use units in all answers. [@ helpLink('units') @]*
END_PGML

#:% section = solution
BEGIN_PGML_SOLUTION
Using dimensional analysis:

a) [```
[$vol] \cdot \frac{1\;\text{l}}{1000\;\text{ml}}
\cdot \frac{1\;\text{qt}}{0.9464\;\text{l}}
\cdot \frac{4\;\text{cups}}{1\;\text{qt}} = [$vol_cups]
```]

b) [```
[$speed] \cdot \frac{1\;\text{mile}}{5280\;\text{ft}}
\cdot \frac{3600\;\text{sec}}{1\;\text{hr}} = [$speed_mph]
```]
END_PGML_SOLUTION

ENDDOCUMENT();
31 changes: 16 additions & 15 deletions tutorial/sample-problems/DiffCalc/AnswerWithUnits.pg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
## MO(1)
## KEYWORDS('differential calculus', 'units')

# Updated 2025.02 to use the contextUnits.pl macro.

#:% name = Answer with Units
#:% type = Sample
#:% subject = differential calculus
Expand All @@ -22,26 +24,25 @@
#: PODLINK('parserFormulaWithUnits.pl') macros.
DOCUMENT();

loadMacros(
'PGstandard.pl', 'PGML.pl',
'parserNumberWithUnits.pl', 'parserFormulaWithUnits.pl',
'PGcourse.pl'
);
loadMacros('PGstandard.pl', 'PGML.pl', 'contextUnits.pl', 'PGcourse.pl');

#:% section = setup
#: First, set the variable for the functions in the problem to be t,
#: and assign the units "seconds" to it.
#:
#: Use the differentiation operator `->D('t')` to compute the derivated, and the
#: evaluation method `->eval()` to evaluate it as a function.
#: evaluation method `->eval()` to evaluate it as a function. All of these will
#: now have the expect units.
Context()->variables->are(t => 'Real');
Context()->assignUnits(t => 's');

$v0 = random(16, 96, 16);

$h = Formula('-16 t^2 + 16');
$h = Formula("(-16 t^2 + $v0 t) ft");
$v = $h->D('t');
$v1 = $v->eval(t => 1);
$v1 = $v->eval(t => $v0 / 16);
$a = $v->D('t');

$ans1 = FormulaWithUnits($v, 'ft/s');
$ans2 = NumberWithUnits($v1, 'ft/s');
$ans3 = FormulaWithUnits($a, 'ft/s^2');

#:% section = statement
#: Give students access to help on entering units and the complete list of units
#: that WeBWorK understands by inserting the result of calling
Expand All @@ -52,16 +53,16 @@ by [`h(t) = [$h]`] for [`t \geq 0`], where time is measured in seconds.

a. What is the velocity of the object? Include units in your answer.

[_]{$ans1}{15}
[_]{$v}{15}

b. What is the velocity of the object when it hits the ground? Include units in
your answer.

[_]{$ans2}{15}
[_]{$v1}{15}

c. What is the acceleration of the object? Include units in your answer.

[_]{$ans3}{15}
[_]{$a}{15}

Note: Use units in all answers. [@ helpLink('units') @]*
END_PGML
Expand Down
62 changes: 62 additions & 0 deletions tutorial/sample-problems/Geometry/LineSegmentGraphTool.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## DESCRIPTION
## Shows a triangle tool within the GraphTool.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
## DBchapter(Sample Problems)
## DBsection(Graph Tool)
## Date(02/25/2025)
## Institution(Missouri Western)
## Author(Glenn Rice)
## MO(1)
## KEYWORDS('graph tool', 'vectors')

#:% name = Line Segment Graph Tool
#:% type = Sample
#:% subject = [geometry]
#:% categories = [graph, graphtool]
#:% see_also = [VectorGraphTool.pg, TriangleGraphTool.pg, QuadrilateralGraphTool.pg]

#:% section = preamble
#: Load the PODLINK('parserGraphTool.pl') macro to be able to use the GraphTool.
DOCUMENT();

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

#:% section = setup
#: The graph tool is created with the correct answer
#: `{ segment, solid, ($sx1, $sy1), ($sx2, $sy2) }`, with unique points
#: `($sx1, $sy1)` and `($sx2, $sy2)`. For a correct answer, the line segment
#: must have the given the endpoints and be solid.
#:
#: Mulitple line segments can be added to the graph tool, however, if a
#: triangle or quadrilateral is desired, see PROBLINK('TriangleGraphTool.pg')
#: and PROBLINK('QuadrilateralGraphTool.pg') for more appropriate tools.
$sx1 = random(-8, 8);
$sy1 = random(-8, 8);
do { $sx2 = random(-8, 8); $sy2 = random(-8, 8); }
until $sx2 != $sx1 || $sy2 != $sy1;

$gt = GraphTool("{segment, solid, ($sx1, $sy1), ($sx2, $sy2)}",)
->with(availableTools => [ 'SegmentTool', 'FillTool', 'SolidDashTool' ]);

#:% section = statement
#: This asks the student to graph the line segment with the given endpoints.
#: The code `[_]{$gt}` inserts the graph tool.
BEGIN_PGML
Graph the line segment between the points [`([$sx1], [$sy1])`] and
[`([$sx2], [$sy2])`].

[_]{$gt}
END_PGML

#:% section = solution
#: To show the graph with alternate text we use the PGML image construct
#: `[! !]{$gt}`, where the alternate text is placed within the `[! !]`.
BEGIN_PGML_SOLUTION
The correct answer is

[!A graph of the line segment from ([$sx1], [$sy1]) to ([$sx2],[$sy2])!]{$gt}
END_PGML_SOLUTION

ENDDOCUMENT();
64 changes: 64 additions & 0 deletions tutorial/sample-problems/Geometry/QuadrilateralGraphTool.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## DESCRIPTION
## Shows a quadrilateral tool within the GraphTool.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
## DBchapter(Sample Problems)
## DBsection(Graph Tool)
## Date(02/25/2025)
## Institution(Missouri Western)
## Author(Glenn Rice)
## MO(1)
## KEYWORDS('graph tool', 'quadrilateral')

#:% name = Quadrilateral Graph Tool
#:% type = Sample
#:% subject = [geometry]
#:% categories = [graph, graphtool]

#:% section = preamble
#: Load the PODLINK('parserGraphTool.pl') macro to be able to use the GraphTool.
DOCUMENT();

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

#:% section = setup
#: This finds four unique random points and sets up the GraphTool. The line
#: `{ quadrilateral, solid, ($x1, $y1), ($x2, $y2), ($x3, $y3), ($x4, y4) }`
#: creates a quadrilateral with solid line edges and the given four points.
$x1 = random(-8, 8);
$y1 = random(-8, 8);
do { $x2 = random(-8, 8); $y2 = random(-8, 8) } until $x2 != $x1 || $y2 != $y1;
do { $x3 = random(-8, 8); $y3 = random(-8, 8) }
until ($y3 - $y1) * ($x2 - $x1) != ($y2 - $y1) * ($x3 - $x1);
do { $x4 = random(-8, 8); $y4 = random(-8, 8) }
until ($y4 - $y1) * ($x2 - $x1) != ($y2 - $y1) * ($x4 - $x1)
&& ($y4 - $y1) * ($x3 - $x1) != ($y3 - $y1) * ($x4 - $x1)
&& ($y4 - $y1) * ($x3 - $x2) != ($y3 - $y2) * ($x4 - $x2);

$gt = GraphTool(
"{quadrilateral, solid, ($x1, $y1), ($x2, $y2), ($x3, $y3), ($x4, $y4)}")
->with(
availableTools => [ 'QuadrilateralTool', 'FillTool', 'SolidDashTool' ]);
#:% section = statement
#: This asks the student to graph a quadrilateral with the given vertices.
#: The code `[_]{$gt}` inserts the graph tool.
BEGIN_PGML
Graph the quadrilateral with vertices [`([$x1], [$y1])`], [`([$x2], [$y2])`],
[`([$x3], [$y3])`], and [`([$x4], [$y4])`] in that order.

[_]{$gt}
END_PGML

#:% section = solution
#: To show the graph with alternate text we use the PGML image construct
#: `[! !]{$gt}`, where the alternate text is placed within the `[! !]`.
$alt_text = "A graph of the quadrilateral with vertices ($x1, $y1), ($x2,$y2), "
. "($x3, $y3),and ($x4, $y4)";
BEGIN_PGML_SOLUTION
The correct answer is

[![$alt_text]!]{$gt}
END_PGML_SOLUTION

ENDDOCUMENT();
Loading