Back to Teaching Page

WeBWork using PGML


Update: November 2024

Links


Reduction Rules

[WeBWork Formula]
[WeBWork Context]
Context()->noreduce("(-x)-y","(-x)+y");

Format Numbers

Context()->{format}{number} = "%.9f";

If Condition

if ( $a > 0 ) {
     $ans = "increasing, concave up";
} 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);

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); } );
        
BEGIN_PGML
[___]{@ans}
END_PGML

Multianswer

loadMacros("parserMultiAnswer.pl");

$fac1 = Formula("(1 - x)");
$fac2 = Formula("(1 + x)");

$multians = MultiAnswer($fac1, $fac2)->with(
  singleResult => 1,
  checker => sub {
    my ( $correct, $student, $self ) = @_;
    my ( $f1stu, $f2stu ) = @{$student};
    my ( $f1, $f2 ) = @{$correct};

    if (($f1stu==$f1 && $f2stu==$f2) || ($f1stu==$f2 && $f2stu==$f1))
          {return 1;}
    else  {return 0;}
    }
);

BEGIN_PGML
Factor

>>[` (1-x^2) =  \Big(`] [___]{$multians} [`\Big)\cdot \Big(`] [___]{$multians} [`\Big)`]<<
END_PGML

Name Pattern and Variable Limits

Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
Context()->variables->are(
	"x" => ["Real", limits => [1,100]],
	"y" => "Real",
	"y'" => "Real",
	"y''" => "Real",
	"C" => "Real",
	"C1" => ["Real", TeX=>"C_1"],
	xk => ["Real",TeX=>"x_k"],
	xk1 => ["Real",TeX=>"x_{k+1}"]);

Set function domains (for answer checker)

$soln =Formula("sqrt(x**2 -$a**2)") -> reduce();
$soln -> {limits}=[abs($a),2*abs($a)];

Answer Help

[@ AnswerFormatHelp("formulas") @]*
[@ AnswerFormatHelp("numbers") @]*
[@ AnswerFormatHelp("matrices") @]*

Add Hyperlinks

_[@ htmlLink("https://www.jirka.org/diffyqs/html/laplacelist_appendix.html", 
"Table of Laplace Transforms", "TARGET='_blank'") @]*_

PGML Solution

BEGIN_PGML_SOLUTION

END_PGML_SOLUTION

Enter a matrix answer

Context("Matrix");

$x = Matrix([[1,4],[2,3]]);

BEGIN_PGML
Enter the matrix [`[$x]`] by entries:

>>[___]*{$x}<<

Enter the matrix [`[$x]`] as [` [[1,4],[2,3]] `]:

>>[___]{$x}<<

END_PGML