WeBWorK Problems

Problems with problems with optional matrices

Re: Problems with problems with optional matrices

by Christopher Heckman -
Number of replies: 0
I've written up a short, complete problem to illustrate the problem I'm having. It asks for a matrix and a number; the matrix is optional, and the problem is supposed to say "correct" in all situations.
----------------------------------

DOCUMENT();

loadMacros(
"PGstandard.pl", 
"MathObjects.pl", 
"PGunion.pl",
"parserMultiAnswer.pl",
"PGcourse.pl",
);

Context ("Matrix");
Context()->parens->set("[" => {formMatrix => 1});

$showPartialCorrectAnswers = 1;
$A = Matrix ([[1,0],[0,1]]);
$B = 42;
$ma = MultiAnswer ($A, $B) -> with (
   singleResult => 1,
   checkTypes => 0,
   allowBlankAnswers => 1,
   checker => sub { 1; }  
   );

TEXT(beginproblem());

BEGIN_TEXT
Enter a matrix and a number. Or don't enter the matrix, if you don't want to.
$PAR
Matrix: \{ $ma -> ans_array \}
$PAR
Number: \{ $ma -> ans_rule \}
END_TEXT

Context()->normalStrings;

ANS ($ma -> cmp);

COMMENT('MathObject version.');

ENDDOCUMENT();

----------------------------------
Oddly enough, if I change the ans_array to ans_rule, WeBWorK does what it is supposed to: Leaving the matrix blank and entering a number is a "correct" answer.