Matrix Operation

Find the product of two matrices if the product is defined.

Complete Code

Download file: MatrixOperations.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

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

Preamble

This uses parserRadioMultiAnswer.pl, so it needs to be loaded.

Context('Matrix');

$A = Matrix([
    [ non_zero_random(-5, 5), non_zero_random(-5, 5) ],
    [ non_zero_random(-5, 5), non_zero_random(-5, 5) ]
]);

$B = Matrix([
    [
        non_zero_random(-5, 5),
        non_zero_random(-5, 5),
        non_zero_random(-5, 5)
    ],
    [
        non_zero_random(-5, 5),
        non_zero_random(-5, 5),
        non_zero_random(-5, 5)
    ],
]);

$rma1 = RadioMultiAnswer(
    [
        ['The product \(AB\) does not exist.'],
        [ 'The product \(AB\) is %s*', $A * $B ]
    ],
    1
);

$rma2 = RadioMultiAnswer(
    [
        ['The product \(BA\) does not exist.'],
        [ 'The product \(BA\) is %s*', $A * $B ]
    ],
    0
);

Setup

First, the two matrices are defined.

A RadioMultiAnswer produces a set of radio buttons for each of the given statements. The format is

 RadioMultiAnswer([
     [statement1],
     [statement2],
     ...
     [last statement]
 ], correct index, options)

Answer blanks can be added with the %s in the string and if a matrix is desired, %s* should be used. See the POD for more details.

BEGIN_PGML
Let
>> [``A = [$A] \quad\text{and}\quad B = [$B].``] <<

1) Select the correct choice below, and fill in any answer boxes within that
choice.

    [____]{$rma1}

2) Select the correct choice below, and fill in any answer boxes within that
choice.

    [____]{$rma2}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.