MatrixAnswer1

From WeBWorK_wiki
Revision as of 05:23, 18 July 2023 by Pstaabp (talk | contribs) (add historical tag and give links to newer problems.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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


Answer is a Matrix 1

Click to enlarge

This PG code shows how to evaluate answers that are matrices.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
);

TEXT(beginproblem());

Initialization:

Context("Matrix");

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

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

$answer = $A * ($B->transpose);

Setup: Use Context("Matrix");. MathObject matrices are constructed using the Matrix() constructor. The matrix A has two rows and three columns, and is constructed by [ [row 1 entries], [row 2 entries] ], and this construction generalizes in the obvious way. If a matrix has only one row, such as B, then it is entered as [row 1 entries] and not as [ [row 1 entries] ]. If $B = Matrix([a,b,c]);, then the matrix $B->transpose is equivalent to Matrix([[a],[b],[c]]); which has an outer pair of brackets enclosing all of the rows, where each row encloses its single element with brackets.

Context()->texStrings;
BEGIN_TEXT
Suppose
\[
A = $A 
\ \ \mbox{and} \ \
B = $B.
\]
Evaluate the following matrix product.
$BR
$BR
\( A B^T = \)
\{ $answer->ans_array(5) \}
\{ AnswerFormatHelp("matrices") \}
END_TEXT
Context()->normalStrings;

Main Text: Use the ->ans_array(width) method on the MathObject matrix $answer to produce an array of answer boxes each with a specified character width.

$showPartialCorrectAnswers = 1;

ANS( $answer->cmp() );

Answer Evaluation: Use standard MathObject answer evaluation.

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area