MatrixOperations1

From WeBWorK_wiki
Jump to navigation Jump to search
This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Matrix Operations

Click to enlarge

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.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"AnswerFormatHelp.pl",
"PGcourse.pl",
);
$showPartialCorrectAnswers = 0;
TEXT(beginproblem()); 

Initialization: We use parserPopUp.pl for the multiple choice part of the question. Use $showPartialCorrectAnswers = 0; to withhold feedback (we will use an all-or-nothing answer grader).

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 ans_box(rows,cols) so that students must find the matrix product dimensions themselves, if the matrix product exists.

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 $A * $B in the Setup section, we did it in the answer section just to show you that it was possible to break "the rules". Standard matrix operations such as +, -, * can be used whenever the matrix operation makes sense.

Templates by Subject Area