Matrix inputs
STACK provides three ways to let students input a matrix:
- The matrix input is a fixed grid, one box for each element.
- The matrix of variable size input is a textarea into which students type in their answer.
- Students can type in the Maxima
matrixcommand into another input, e.g. the default algebraic input.
Matrix input
The size of the matrix is inferred from the model answer. STACK then adds an appropriate grid of boxes (of size Box Size) for the student to fill in. This is easier than having students type in Maxima's matrix command, but does give the game away about the size of the required matrix.
The grid normally returns a Maxima matrix(...). A column_vector(...) or row_vector(...)
model answer instead gives a vector input with the corresponding shape. This keeps vectors and
one-row or one-column matrices distinct. Use vec_convert(...) in a PRT when an answer test
requires a matrix. See Vectors for convenience aliases.
The student may not fill in part of a matrix. If they do so, the remaining entries will be completed with ? characters which render the attempt invalid. STACK cannot cope with empty boxes here.
We cannot use the EMPTYANSWER tag for the teacher's answer with the matrix input, because the size of the matrix is inferred from the model answer. If a teacher really wants a correct answer to be a completely empty input then they must use a correctly formatted matrix with null values
ta:transpose(matrix([null,null,null]));
The brackets around the HTML inputs are taken from the question-level matrixparens option. The left and right
delimiters are also exposed as labelled mathematical elements for assistive technologies.
Vector expressions also use matrixparens, giving inputs and their validation display a common
delimiter choice. Independent matrix and vector delimiter settings are discussed in
#1848.
Augmented matrix inputs
Use an augmented model answer directly:
A:matrix([1,2],[3,4]);
b:column_vector(5,6);
ta:aug(A,b);
Choose the fixed matrix input with model answer ta. Its instantiated value is
aug_matrix(matrix([1,2],[3,4]),column_vector(5,6)): the grid automatically has two rows, three columns
and an internal separator after column two. Multiple blocks such as aug(A,B,C) work in the
same way. Blocks may be matrices or vectors and must be nonempty with equal
row counts. No separate boundary option is required.
The student fills one grid. Submission and validation reconstruct the same augmented constructor and block types, and the validation echo displays the augmented matrix again. Saved responses, model answers and syntax hints are mapped back to the same cells. Ordinary matrix inputs retain their current behaviour.
The teacher and student values can be compared as augmented objects. For answer tests which require
an ordinary matrix, use de_aug(ans1) (and de_aug(ta) where appropriate). aug, its display rules
and de_aug are available in the linear-algebra core; no contributed-library load is required.
API consumers receive casValueType: "aug_matrix" and a blocks array, for example
[{"type":"matrix","columns":2},{"type":"column_vector","columns":1}]. Use these widths for grid boundaries
and reconstruct each block with its indicated constructor. Vector types use the model's exact
constructor name, including column_vector and row_vector.
Field names and the native Moodle AJAX grid format do not change.
Matrix of variable size input
The matrix of variable size input is a textarea into which students type in their answer. For a matrix, students separate entries in each row with spaces and separate rows with line breaks.
As with the fixed grid, a vector model answer makes the input return a vector. Spaces and line
breaks both separate components: 1 2 3 and the same components on separate lines give the same
value. The model answer determines its orientation, so a column_vector(...) model produces
column_vector(1,2,3), and a row_vector(...) model produces row_vector(1,2,3).
Input box size is used to determine the starting width of the input.
If you use the allowempty option then an empty answer is indicated by the EMPTYANSWER tag. This is a different type than a matrix. (We could have chosen matrix() as the empty matrix, but EMPTYANSWER is more in keeping with other inputs.)
Augmented matrices of variable size
The variable-size matrix textarea also accepts an augmented model answer such as aug(A,b).
Students separate entries with spaces, rows with newlines, and blocks with | on every row:
1 2 | 5
3 4 | 6
Rows and matrix-block widths are student-selected; the model does not fix their dimensions. The model does fix the number and constructor types of blocks. A column-vector block must remain one column and a row-vector block must remain one row. Matrix blocks can have any positive number of columns. Every row must have the same nonempty block widths. Missing or inconsistent separators are validation errors. For a malformed block structure, validation shows a short multi-line example:
1 ... | 2
3 ... | 4
The feedback explicitly leaves the row count open. Models containing a row-vector block show only one row. The dots stand for optional extra entries in a matrix or row-vector block; a column-vector block contains just one entry. The example uses neither the teacher's entries nor matrix-block dimensions. Feedback reminds students to keep block widths consistent between rows, or use only one row when the model contains a row-vector block.
Submitted answers preserve aug_matrix(...) and the block constructors, and validation renders the
augmented matrix with the selected outer bracket style. Model answers, syntax hints, saved responses
and AJAX validation use the same bar-separated textarea representation. Ordinary matrices retain
their existing space/newline syntax. The row/column-vector behaviour previously introduced in #1847
is preserved.
The textarea wrapper exposes data-stack-input-value-type="aug_matrix". API clients receive
casValueType, blockTypes and blockSeparator metadata. These are input-surface hooks; a dedicated
CSS wrapper around augmented MathJax output is not introduced here.