MatrixOperations1
Matrix Operations
This PG code shows how to assess whether a student knows whether two matrices can be multiplied and, when the matrix product exists, what the dimensions of a matrix product are.
- File location in OPL: FortLewis/Authoring/Templates/LinAlg/MatrixOperations1.pg
- More problems like this in the OPL: Hope/Multi1/02-01-Matrix-operations/
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserPopUp.pl", "AnswerFormatHelp.pl", "PGcourse.pl", ); $showPartialCorrectAnswers = 0; TEXT(beginproblem()); |
Initialization:
We use |
Context('Matrix'); $A = Matrix([ [non_zero_random(-5,5,1),non_zero_random(-5,5,1)], [non_zero_random(-5,5,1),non_zero_random(-5,5,1)], ]); $B = Matrix([ [non_zero_random(-5,5,1),non_zero_random(-5,5,1),non_zero_random(-5,5,1)], [non_zero_random(-5,5,1),non_zero_random(-5,5,1),non_zero_random(-5,5,1)], ]); $popup = PopUp(['Choose','True','False'],'False'); |
Setup: Create two 2 by 3 matrices and a true/false popup. |
Context()->texStrings; BEGIN_TEXT Let \[ A = $A,\] \[ B = $B.\] If possible, compute the following. If an answer does not exist, enter ${BBOLD}DNE${EBOLD}. $BR $BR \( AB = \) \{ ans_box(3,30).$SPACE.AnswerFormatHelp('matrices') \} $BR $BR \( BA = \) \{ ans_box(3,30).$SPACE.AnswerFormatHelp('matrices') \} $BR $BR \{ $popup->menu \} True or False: For any two matrices \( A \) and \( B \), both of the products \( AB \) and \( BA \) are always defined. END_TEXT Context()->normalStrings; |
Main Text:
Use |
install_problem_grader(~~&std_problem_grader); ANS( ($A * $B)->cmp() ); ANS( Compute('DNE')->cmp() ); ANS( $popup->cmp ); COMMENT('MathObject version.'); ENDDOCUMENT(); |
Answer Evaluation:
Use the standard problem grader, which awards full credit only when all answers are correct and zero credit otherwise. Although it would have been better coding practice to construct the matrix product |