From WeBWorK
(Difference between revisions)
Jump to: navigation, search
Paultpearson (Talk | contribs)
(Add new matrices and custom answer checkers template)
Newer edit →

Revision as of 21:04, 28 June 2014

Matrices and Custom Answer Checkers

Click to enlarge

This PG code shows how to use a multianswer answer checker to evaluate an open-ended question about matrices.

Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

$showPartialCorrectAnswers = 0;



$A = Matrix([[1,1],[0,1]]);
$B = Matrix([[1,0],[1,1]]);

$multians = MultiAnswer($A, $B)->with(
  singleResult => 1,
  checker => sub {
      my ( $correct, $student, $answerHash ) = @_;
      my @s = @{$student};
      $s0 = Matrix($s[0]); 
      $s1 = Matrix($s[1]);
      return $s0 * $s1 != $s1 * $s0;

Setup: Construct two matrices $A and $B that do not commute and therefore serve as a correct answer. Use a $multians object with a custom answer checker subroutine. The answer checker uses my ( $correct, $student, $answerHash ) = @_; to grab the inputs (the correct answer, the student answer, and the answer hash table info). Then, put the student's two answers into an array @s using my @s = @{$student};. Make sure the student's first matrix $s[0] is converted to a MathObject matrix $s0 using $s0 = Matrix($s[0]); and similarly for the student's second matrix. The return value, which is boolean, is the truth value of the statement $s0 * $s1 != $s1 * $s0.

Give an example of two \( 2 \times 2 \) matrices \( A \) and \( B \)
such that \( AB \ne BA \).
\( A = \)
\{ $multians->ans_array(5) \}
\( B = \)
\{ $multians->ans_array(5) \}

Main Text: Make sure that both answer arrays are called as methods on the $multians object (i.e., $multians->ans_array(5) should be called for each answer array. Note that ans_array(w) produces an answer array of boxes each w characters wide.


ANS( $multians->cmp() );

COMMENT('MathObject version.');


Answer Evaluation:

Templates by Subject Area

follow us