Custom Matrix Answer Checker

Answer is a pair of matrices that require a custom answer checker

Complete Code

Download file: MatrixCustomAnswerChecker.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserMultiAnswer.pl', 'PGcourse.pl');

$showPartialCorrectAnswers = 0;

Preamble

Since the answer will depend on two matrix inputs at once, the parserMultiAnswer.pl macro must be loaded.

Context('Matrix');

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

$multians = MultiAnswer($A, $B)->with(
    singleResult => 1,
    checker      => sub {
        my ($c, $s, $ansHash) = @_;
        return $s->[0] * $s->[1] != $s->[1] * $s->[0] ? 1 : 0;
    }
);

Setup

Construct two matrices $A and $B that do not commute. Use a $multians object with a custom answer checker subroutine. The answer checker uses my ($c, $s, $ansHash) = @_ to extract the inputs (the correct answer, the student answer, and the answer hash). The checker returns 1 if $s->[0] * $s->[1] != $s->[1] * $s->[0] is true and 0 otherwise. Note that $s->[0] is the MathObject representation of the student’s answer for the first matrix, and $s->[1] is the MathObject representation of the student’s answer for second matrix.

BEGIN_PGML
Give an example of two [`2 \times 2`] matrices [`A`] and [`B`] such that
[`AB \ne BA`] .

    [`A =`] [_____]*{$multians}

    [`B =`] [_____]*{$multians}
END_PGML

Statement

Make sure that both answer arrays are called as methods on the $multians object.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.