Skip to content

Commit 1775178

Browse files
committed
Adding more sample problems and cleanup
1 parent 5f5b815 commit 1775178

18 files changed

+748
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
## DESCRIPTION
2+
## Factored polynomial
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(WeBWorK)
6+
## DBchapter(WeBWorK tutorial)
7+
## DBsection(PGML tutorial 2015)
8+
## Date(06/01/2015)
9+
## Institution(Hope College)
10+
## Author(Paul Pearson)
11+
## Static(1)
12+
## MO(1)
13+
## KEYWORDS('algebra', 'factored polynomial')
14+
15+
#:% name = Simple factoring
16+
#:% type = Sample
17+
#:% subject = [algebra, precalculus]
18+
#:% categories = [polynomial]
19+
#:% see_also = [FactoredPolynomial.pg, ExpandedPolynomial.pg, FactoringAndExpanding.pg]
20+
21+
#:% section = preamble
22+
DOCUMENT();
23+
24+
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
25+
#:% section = setup
26+
#: First, we create two random roots and then create the factors. Note:
27+
#: the `->reduce` will help make `x-(-3)` into `x+3`. In addition, we
28+
#: create the expanded form of the quadratic.
29+
#:
30+
#: Note that the argument of the List call are the objects in the list,
31+
#: which can be any MathObjects. Here we create a list of Formulas and a list
32+
#: of Reals (the numbers that we use in the second list will be promoted to
33+
#: Real MathObjects when the List is created).
34+
#:
35+
#: If, for example, there were no real roots, we should set
36+
#: `$roots = List("NONE");` so that students who enter a list of roots will not
37+
#: receive an error message about entering the wrong type of answer. If we were
38+
#: to use `$roots = String("NONE");` instead, students who enter anything
39+
#: other than a string (e.g., a list of numbers) will receive an error message.
40+
#:
41+
#: Similarly, if there were only one root at x=4, we would use
42+
#: `$roots = List(4);` instead of $roots = Real(4); to avoid sending error
43+
#: messages to students who enter multiple answers or NONE.
44+
($x0, $x1) = (non_zero_random(-6, 6), non_zero_random(-6, 6));
45+
$factor1 = Compute("x-$x0")->reduce;
46+
$factor2 = Compute("x-$x1")->reduce;
47+
$f = Compute("x^2-($x0+$x1)x+$x0*$x1")->reduce;
48+
$factors = List($factor1, $factor2);
49+
$roots = List($x0, $x1);
50+
51+
# If there were only one solution
52+
# $roots = List(4);
53+
54+
# If there were no solutions
55+
# $roots = List("NONE");
56+
57+
#:% section = statement
58+
BEGIN_PGML
59+
a) What are the factors of [`[$f]`]?
60+
61+
Factors = [__]{$factors}
62+
63+
64+
b) What are the roots of this equation?
65+
66+
Roots = [__]{$roots}
67+
68+
_(Enter both answers as a comma-separated list.)_
69+
70+
END_PGML
71+
72+
#:% section = solution
73+
BEGIN_PGML_SOLUTION
74+
Solution explanation goes here.
75+
END_PGML_SOLUTION
76+
77+
ENDDOCUMENT();

tutorial/sample-problems/Misc/EssayAnswer.pg

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# http://webworkgoehle.blogspot.com/2012/09/essay-answers-in-webwork.html
1616

1717
#:% name = Essay Answer
18-
#:% type = Sample
18+
#:% type = [Sample, technique]
1919
#:% categories = [essay]
2020

2121
#:% section = preamble

tutorial/sample-problems/Misc/Matching.pg

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ loadMacros(
4848
#: 'None of the above' answer that will be made last with `makeLast`.
4949
#: So the popup list must have 9 entries A through I.
5050
#:
51-
#: As an alternative, see PROBLINK('MatchingAlt.pl') for another way to write
51+
#: As an alternative, see PROBLINK('MatchingAlt.pg') for another way to write
5252
#: a matching problem.
5353
$showPartialCorrectAnswers = 0;
5454

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
## DESCRIPTION
2+
## Matching problem with graphs
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(WeBWorK)
6+
## DBchapter(WeBWorK tutorial)
7+
## DBsection(PGML tutorial 2015)
8+
## Date(07/15/2023)
9+
## Institution(Fitchburg State University)
10+
## Author(Peter Staab)
11+
## MO(1)
12+
## KEYWORDS('matching', 'dynamic graph')
13+
14+
#:% name = Matching Problem with Graphs
15+
#:% type = Sample
16+
#:% subject = [algebra, precalculus]
17+
#:% categories = [graph]
18+
19+
#:% section = preamble
20+
#: The dynamic graph is generated with `PGtikz.pl`, so this is needed.
21+
#: The matching is done with popups, so `parserPopUp.pl` is need and lastly
22+
#: a `LayoutTable` is used from `niceTables.pl`.
23+
DOCUMENT();
24+
25+
loadMacros(
26+
'PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'parserPopUp.pl',
27+
'niceTables.pl', 'PGcourse.pl'
28+
);
29+
30+
#:% section = setup
31+
#: The array `@all_plots` contains the display form (f) of the function,
32+
#: the functional form (form) of the function needed in tikz format,
33+
#: the domain of the function and the alterative text.
34+
#:
35+
#: The graphs of all plots and then created by calling commands from `PGtikz.pl`.
36+
#: See PROBLINK('DynamicGraph.pg') for a simpler example using tikz. Note
37+
#: that alternate text is provided to the `image` command and for accessibility
38+
#: should always be considered and this should be provided.
39+
#:
40+
#: The dropdowns are created in the `@dropdown` array which pulls all
41+
#: options.
42+
#:
43+
#: The `LayoutTable` is used to make an accessible table that is nicely
44+
#: laid out.
45+
#:
46+
#: Although this matching problem creates graphs dynamically, these can use
47+
#: static images by changing the call to `image` to just pass in the
48+
#: image names.
49+
@all_plots = (
50+
{
51+
f => 'x^2',
52+
form => '\x*\x',
53+
domain => '-3:3',
54+
alt =>
55+
'A graph of a curve with a minimum at the origin and opening '
56+
. 'upward.'
57+
},
58+
{
59+
f => 'e^x',
60+
form => 'exp(\x)',
61+
domain => '-6:3',
62+
alt => 'A graph of a curve starting near the negative x axis and '
63+
. 'rising steeply toward the first quadrant.'
64+
},
65+
{
66+
f => 'x^3',
67+
form => '\x*\x*\x',
68+
domain => '-2:2',
69+
alt => 'A graph of a curve from the third quadrant (where is it '
70+
. 'concave down) to the first quadrant (where it is concave up).'
71+
},
72+
{
73+
f => 'ln(x)',
74+
form => 'ln(\x)',
75+
domain => '0.1:6',
76+
alt => 'A graph of a curve that approaches the negative y-axis '
77+
. 'and rises to the first quadrant and everywhere it is concave'
78+
. 'down.'
79+
},
80+
{
81+
f => '3x+2',
82+
form => '3*\x+2',
83+
domain => '-6:6',
84+
alt =>
85+
'The graph of a line from the 3rd quadrant to the first quadrant'
86+
},
87+
{
88+
f => 'sin(x)',
89+
form => 'sin(\x r)',
90+
domain => '-6:6',
91+
alt => 'A graph of a curve that osciallates and passes through the '
92+
. 'origin'
93+
},
94+
);
95+
96+
for $i (0 .. $#all_plots) {
97+
my $graph = createTikZImage();
98+
$graph->tikzLibraries('arrows.meta');
99+
$graph->BEGIN_TIKZ
100+
\tikzset{>={Stealth[scale=1.5]}}
101+
\filldraw[
102+
draw=LightBlue,
103+
fill=white,
104+
rounded corners=10pt,
105+
thick,use as bounding box
106+
] (-7,-7) rectangle (7,7);
107+
\draw[->,thick] (-6,0) -- (6,0) node[above left,outer sep=3pt] {\(x\)};
108+
\foreach \x in {-5,...,-1,1,2,...,5}
109+
\draw(\x,5pt) -- (\x,-5pt) node [below] {\(\x\)};
110+
\draw[->,thick] (0,-6) -- (0,6) node[below right,outer sep=3pt] {\(y\)};
111+
\foreach \y in {-5,...,-1,1,2,...,5}
112+
\draw (5pt,\y) -- (-5pt,\y) node[left] {\(\y\)};
113+
\draw[blue,ultra thick] plot[domain=$all_plots[$i]->{domain},smooth] (\x,{$all_plots[$i]->{form}});
114+
END_TIKZ
115+
$all_plots[$i]->{graph} = $graph;
116+
}
117+
118+
@plots = random_subset(4, @all_plots);
119+
120+
# sorted list of possible answers
121+
$list = [ lex_sort(map {"$_->{f}"} @all_plots) ];
122+
123+
@dropdowns = map { DropDown($list, "$_->{f}") } @plots;
124+
125+
$tab = LayoutTable(
126+
[
127+
[
128+
map {
129+
image(
130+
$plots[$_]->{graph},
131+
width => 300,
132+
tex_size => 400,
133+
extra_html_tags => "alt = '$plots[$_]->{alt}'"
134+
)
135+
} (0 .. 1)
136+
],
137+
[ map { $dropdowns[$_]->menu } (0 .. 1) ],
138+
[
139+
map {
140+
image(
141+
$plots[$_]->{graph},
142+
width => 300,
143+
tex_size => 400,
144+
extra_html_tags => "alt = '$plots[$_]->{alt}'"
145+
)
146+
} (2 .. 3)
147+
],
148+
[ map { $dropdowns[$_]->menu } (2 .. 3) ]
149+
150+
],
151+
align => 'cc'
152+
);
153+
154+
$showPartialCorrectAnswers = 0;
155+
156+
#:% section = statement
157+
BEGIN_PGML
158+
Match the graph with the formula for the graph (Click on image for a larger view.)
159+
160+
[$tab]*
161+
END_PGML
162+
163+
#:% section = answer
164+
#: Because the dropdowns are created in the older fashion, we use the `ANS` form
165+
#: to check the answer
166+
ANS($dropdowns[$_]->cmp) for (0 .. 3);
167+
168+
#:% section = solution
169+
BEGIN_PGML_SOLUTION
170+
Solution explanation goes here.
171+
END_PGML_SOLUTION
172+
173+
ENDDOCUMENT();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## DESCRIPTION
2+
## Check student answers that are parametric equations
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(WeBWorK)
6+
## DBchapter(WeBWorK tutorial)
7+
## DBsection(PGML tutorial 2015)
8+
## Date(06/01/2015)
9+
## Institution(Hope College)
10+
## Author(Paul Pearson)
11+
## Static(1)
12+
## MO(1)
13+
## KEYWORDS('parametric equation', 'answer checker')
14+
15+
#:% name = Parametric Equation Answer Checker
16+
#:% type = [Sample, technique]
17+
#:% subject = [differential calculus]
18+
#:% categories = [parametric, answer]
19+
20+
#:% section = preamble
21+
#: Since there are multiple ways to parameterize, we use the `parserMultiAnswer.pl`
22+
#: macro.
23+
DOCUMENT();
24+
25+
loadMacros('PGstandard.pl', 'PGML.pl', 'parserMultiAnswer.pl', 'PGcourse.pl');
26+
27+
#:% section = setup
28+
#: We use a `MultiAnswer()` answer checker that will verify that the students
29+
#: answers satisfy the equation for the circle and have the required starting
30+
#: and ending points. This answer checker will allow students to enter any
31+
#: correct parametrization. For example, both
32+
#: x = \cos(t), y = sin(t), 0 ≤ t ≤ pi/3 and x = cos(2t), y = sin(2t),
33+
#: 0 ≤ t ≤ pi/6 will be marked correct.
34+
#:
35+
#: When evaluating student's answers, it is important not to use quotes. For
36+
#: example, if the code were `$xstu->eval(t=>"$t1stu")` with quotes, then if a
37+
#: student enters pi the answer checker will interpret it as the string "pi"
38+
#: which will need to be converted to a MathObject Real and numerical error
39+
#: will be introduced in the conversion. The correct code to use is
40+
#: `$xstu->eval(t=>$t1stu)` without quotes so that the answer is interpreted
41+
#: without a conversion that may introduce error.
42+
#:
43+
#: The first if statement is fully correct, that is the parametric functions
44+
#: are on the unit circle and the initial and final points are correct.
45+
#: The other three ifelse in the answer checker has either the second point,
46+
#: first point or both points wrong.
47+
Context("Numeric")->variables->are(t => "Real");
48+
Context()->variables->set(t => { limits => [ -5, 5 ] });
49+
50+
$x = Formula("cos(t)");
51+
$y = Formula("sin(t)");
52+
$t0 = Compute("0");
53+
$t1 = Compute("pi/3");
54+
55+
($x0, $y0) = (1, 0);
56+
($x1, $y1) = (1 / 2, sqrt(3) / 2);
57+
58+
$multians = MultiAnswer($x, $y, $t0, $t1)->with(
59+
singleResult => 0,
60+
checker => sub {
61+
my ($correct, $student, $self) = @_;
62+
my ($xstu, $ystu, $t0stu, $t1stu) = @{$student};
63+
if ((($xstu**2 + $ystu**2) == 1)
64+
&& (($xstu->eval(t => $t0stu)) == $x0)
65+
&& (($ystu->eval(t => $t0stu)) == $y0)
66+
&& (($xstu->eval(t => $t1stu)) == $x1)
67+
&& (($ystu->eval(t => $t1stu)) == $y1))
68+
{
69+
return [ 1, 1, 1, 1 ];
70+
71+
} elsif ((($xstu**2 + $ystu**2) == 1)
72+
&& (($xstu->eval(t => $t0stu)) == $x0)
73+
&& (($ystu->eval(t => $t0stu)) == $y0))
74+
{
75+
return [ 1, 1, 1, 0 ];
76+
77+
} elsif ((($xstu**2 + $ystu**2) == 1)
78+
&& (($xstu->eval(t => $t1stu)) == $x1)
79+
&& (($ystu->eval(t => $t1stu)) == $y1))
80+
{
81+
return [ 1, 1, 0, 1 ];
82+
83+
} elsif ((($xstu**2 + $ystu**2) == 1)) {
84+
return [ 1, 1, 0, 0 ];
85+
86+
} else {
87+
return [ 0, 0, 0, 0 ];
88+
}
89+
}
90+
);
91+
#:% section = statement
92+
#: Since the correct answer depends on all answer blanks, the MathObject
93+
#: `$multians` is input into all answer blanks.
94+
BEGIN_PGML
95+
Find a parametrization of the unit circle from the point
96+
[` \big(1,0\big) `] to [` \big(\frac{1}{2},\frac{\sqrt{3}}{2}\big) `].
97+
Use [` t `] as the parameter for your answers.
98+
99+
[` x(t) = `] [__]{$multians}
100+
101+
[` y(t) = `] [__]{$multians}
102+
103+
for [__]{$multians} to [__]{$multians}.
104+
END_PGML
105+
106+
#:% section = solution
107+
BEGIN_PGML_SOLUTION
108+
Solution explanation goes here.
109+
END_PGML_SOLUTION
110+
111+
ENDDOCUMENT();

tutorial/sample-problems/Parametric/PolarGraph.pg

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
## KEYWORDS('parametric', 'graph polar curve')
1313

1414
#:% name = Polar Graph
15-
#:% type = Sample
15+
#:% type = [sample, technique]
1616
#:% subject = parametric
1717

1818
#:% section = preamble

0 commit comments

Comments
 (0)