## WeBWorK Main Forum

### Matrix option: tolerance broken?

by Andrew Dabrowski -
Number of replies: 3
Does the tolerance option in Matrix objects actually do anything? Here's a MWE.

DOCUMENT();
loadMacros(
 "PGbasicmacros.pl",
 "PGanswermacros.pl",
 "MathObjects.pl"
);
TEXT(beginproblem);
Context("Matrix");
$val = 0.5644; $mat = Matrix([[$val]]); BEGIN_TEXT  \{$mat->ans_array \}
 $BR$BR

 \{ans_rule(8)\}

END_TEXT

ANS($mat->cmp( tolerance => 0.0001,tolType => 'absolute' ) ); ANS(num_cmp($val, 'tol' => 0.0001 ));
ENDDOCUMENT();

When the number 0.564 is entered in both blanks, the first (in the matrix) is marked correct while the second (a scalar) is marked incorrect. Shouldn't both be incorrect?

### Re: Matrix option: tolerance broken?

by Andrew Dabrowski -
Nothing?

### Re: Matrix option: tolerance broken?

by Davide Cervone -
It is a bug. The context is losing track of the AnswerHash that is currently in play (due to the way answer arrays are being processed, though I haven't tracked down the exact reason yet).

As a work-around, you could use

$mat = Matrix([[$val]])->with(tolerance => .0001, tolType => 'absolute');

when creating the matrix instead. This puts the tolerance and tolTpe on the matrix itself rather than on the answer checker (and so in the AnswerHash that is being lost along the way). Or you could put them in the Context itself. Or could use a custom answer checker to reattach the AnswerHash to the context.

Any of those would be a work-around to get the proper tolerances for now.