Answer is a matrix
Download file: MatrixAnswer2.pg
DOCUMENT(); loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
Preamble
These standard macros need to be loaded.Context('Matrix'); $example1 = Matrix([ [ 1, 2, 3 ], [ 4, 5, 6 ] ]); $example2 = $example1->column(1); $example3 = $example1->row(1);
Setup
Use Context('Matrix');
. We construct a 2 by 3 matrix and extract its first column and first row.
BEGIN_PGML The purpose of this question is to show you the syntax needed to enter matrices in WeBWorK when there is only one answer box for entering a matrix (which is not obvious) or when there are multiple answer boxes for entering a matrix (which is obvious). The examples below should be self-explanatory, so you can jump to them if you want; however, a detailed explanation follows if you want to read more. Matrices use square brackets to enclose items in lists. A matrix with one row, such as a row vector, is a comma separated list enclosed by square brackets. A matrix with more than one row or a column vector is a comma separated list of lists, where each list uses square brackets to enclose its items. Your answers must use square brackets to enclose each row in a matrix or in a column vector. Also, a pair of square brackets is needed to enclose a matrix with more than one row (e.g., a [`2 \times 3`] matrix and a [`2 \times 1`] column vector have multiple rows so they need extra square brackets, but a [`1 \times 3`] row vector has only one row so it does not need extra square brackets). Your answers may have spaces and line breaks in them, such as >> [| [ [1, 2, 3], |] << >> [| [4, 5, 6] ] |] << + Enter the matrix [``[$example1]``] as [@ $example1->string @]* [@ ans_box(3,30) @]* + Enter the column vector [``[$example2]``] as [@ $example2->string @]* [@ ans_box(3,30) @]* + Enter the row vector [``[$example3]``] as [@ $example3->string @]* [@ ans_box(3,30) @]* END_PGML
Statement
This is the problem statement in PGML.ANS($example1->cmp); ANS($example2->cmp); ANS($example3->cmp);
Answer
Because an ans_box
is used, we need to use the older style answer checkers.
Context('Matrix'); $example4 = Matrix([ [ 1, 2, 3 ], [ 4, 5, 6 ] ]);
Setup2
Reset the context because the matrix answer checker gets confused when the ans_box
and ans_array
methods are co-mingled.
BEGIN_PGML [$BR]* + Entering a matrix using multiple answer blanks is straightforward -- just put each matrix entry into its own answer blank. Enter the matrix [`` [$example4] ``] with one matrix entry per answer box. [______]*{$example4} END_PGML ENDDOCUMENT();
Statement2
This is the other method to entering matrices.