Back to Teaching Page

WeBWork Resources


Reduction Rules

[WeBWork Formula]
[WeBWork Context]

Context()->noreduce("(-x)-y","(-x)+y");


Aternative Correct Answers

$x1 = Formula("A * cos($w*t) + B * sin($w*t)")->reduce;
$x2 = Formula("A * sin($w*t) + B * cos($w*t)")->reduce;

ANS( $x1->cmp( checker=>sub {
   my ( $correct, $student, $ansHash ) = @_;
return ($student == $x1) || ($student == $x2);
} ) );


Unordered Answers

loadMacros("unorderedAnswer.pl")

$showPartialCorrectAnswers = 1;

$factor1 = Formula("x-$a")->reduce;
$factor2 = Formula("x-$b")->reduce;
UNORDERED_ANS( $factor1->cmp(), $factor2->cmp() );


If Condition

} else {
     $ans = "decreasing, concave down"; }


Do Loop

$a = non_zero_random(-9, 9, 1);
do {$b = non_zero_random(-9, 9, 1);} until ($b != $a);


Name Pattern

Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
Context()->variables->add(
       "y" => "Real",
       "y'" => "Real",
       "y''" => "Real",
       "C1" => "Real",
       "C2" => "Real",
);


Correct Answers up to a Multiplicity

$ans = Formula("x^2+y^2");
ANS( $ans->cmp( checker=>sub {
     my ( $correct, $student, $ansHash ) = @_;
     $tmp = Formula("$student/$ans");
return ( Formula($tmp->D('x'))==Formula(0) &&
       ( Formula($tmp->D('t'))==Formula(0) &&
       ( Formula($tmp->D('X'))==Formula(0)
} ) );


Sytem of Linear Equations with Answer Entries

loadMacros("PGmatrixmacros.pl");

System of linear equations
\{ mbox(
display_matrix([[ans_rule(1), "0" , "0", "0"],
       [ans_rule(1),ans_rule(1), "0", "0"],
       ["0",ans_rule(1),ans_rule(1), "0"],
       ["0","0",ans_rule(1),ans_rule(1)]], 'align'=>"cccc"),
display_matrix([["\(m_1\)"], ["\(m_2\)"], ["\(m_3\)"], ["\(m_4\)"]], 'align'=>"c"),
"=",
display_matrix([[ans_rule(1)], [ans_rule(1)], [ans_rule(1)], [ans_rule(1)]], 'align'=>"c")
)\}


Layout Table

loadMacros("niceTables.pl");

\{LayoutTable(
[
     ['\(1^2={}\)'.ans_rule(3),'\(2^2={}\)'.ans_rule(3)],
     ['\(3^2={}\)'.ans_rule(3),'\(4^2={}\)'.ans_rule(3)],
],
align => 'r | r',
center => 0,
);\}


Add Solution

Context()->texStrings;
BEGIN_SOLUTION
...
END_SOLUTION


Draw Graphs of Functions

$a = random(1,2); # left end
$c = $a+random(1,2); # parabola vertex x
$b = 2*$c-$a+1; # the right end is above the left end
$y1c = random(1,2); # vertex y


# parabola
$y1 = Formula("x^2-(2*$c)*x + ($c*$c+$y1c)")->reduce;
$y1a = $y1 -> eval(x=>$a);
$y1b = $y1 -> eval(x=>$b);

# line defined by 2 points (a,y2a) and (b,y2b)
$y2a = $y1a;
$y2b = $y1b;
$y2 = Formula("(($y2b-$y2a)/($b-$a))*x + ($y2a-$a*(($y2b-$y2a)/($b-$a)))")->reduce;

# GRAPH
$xmin = min($a,0)-1;
$xmax = $b+1;
$ymin = -1;
$ymax = max($y2a,$y2b)+1;

$gr = init_graph($xmin,$ymin,$xmax,$ymax,
  axes=>[0,0],
  grid=>[$xmax-$xmin,$ymax-$ymin],
  size=>[300,300]
);

add_functions($gr, "$y1 for x in <$a,$b>" . " using color:blue and weight:2");
add_functions($gr, "$y2 for x in <$a,$b>" . " using color:blue and weight:2");

# vertical line
$gr->moveTo($a,$y1a);
$gr->lineTo($a,$y2a,'blue',2);

# add points
$gr->stamps(closed_circle($a,$y1a,'red',10) );
$gr->stamps(closed_circle($b,$y1b,'red',10) );

Context()->texStrings;
BEGIN_TEXT
Let \(R\) be the region bounded by the curves \(y=$y1\) and \(y=$y2\).

$PAR
$BCENTER
\{ image( insertGraph($gr), width=>300,height=>300,tex_size=>800 ) \}
$BR
(Click on graph to enlarge)
$ECENTER