Matrix Editor

Using the Matrix editor, it is possible to have questions where the answer contains many pieces of automatically gradable information. Of course the main intention is to make creating questions with matrices as the answer easy to implement, but the matrix entries are customizable to allow other uses. See question 215686 for a working example incorporating many of the functions.

This type of question is incredibly powerful but very particular on how responses will be received (ie additional line of code needed for answers to be in fraction instead of decimal format).

Why bother?

Use the matrix data type if you want to easily display a matrix in the question text, or have a matrix as the answer to the question. Matrices are fully functional in the matrix (HTML & Javascript) editor, but using them as a datatype in the other (TeX & Javascript/C) editors may not be supported.

Note: For the TeX & JavaScript editor, math.js does have a .toTex() function implemented for each matrix object.


Table of Contents:


How to use Matrices in the Code Block

To specify a matrix type parameter or answer, use the keyword matrix in the variable declaration:

/* global matrix ans1 u={} */

But when using matrix objects, make sure to convert them to JSON strings before exiting the function:

ans1 = JSON.stringify(ans1._data);

This variable indicates whether maxima should be used to evaluate the student's responses. value=1 indicates that maxima should be used. This variable should be present if, for example, answers are a complex value like "5x + 3i" . For example,

/* global int maxima_1 u={} */

maxima_1 = 1;

indicates that the student response to part 1 should be evaluated with maxima.

Strings as Matrix entries

It is valid to use strings as matrix entries, this can be useful when asking students to enter fractions as part of their answer. If the maxima_N flag is on, then the text submitted will be evaluated for equivalency with the Maxima computer algebra system.

/* global matrix ans1 u={} */

/* global int maxima_1 u={} */

maxima_1 = 1;

ans1 = math.matrix([["1/2"],["1"],["1+i"]]);

ans1 = JSON.stringify(ans1._data);

Optional cell properties


Here's the key thing to remember: we use a set of optional matrices, each the same size as the original, to indicate prefixes, suffixes, and other properties related to a particular cell. Each of these matrices has a name of the form name_n, where n is the problem part whose matrix answer is associated with this optional matrix.

A working example

For example:


/* global matrix responsem_1 u={} */


applies to the answer matrix associated with problem part 1, ans1.


Prefix value for cell


/* global matrix seedpre_1 u={} */


specifies the character string to appear before the cell, e.g. "sin("


Suffix value for cell


/* global matrix seedsuf_1 u={} */


specifies the character string to appear after the cell, e.g. ")"


Seed cell for cell


/* global matrix seedm_1 u={} */


specifies the character string to appear inside the cell, e.g. "5x + i"


Cell prompt flag


/* global matrix responsem_1 u={} */


indicates whether the cell is an input field or not; value=1 indicates an input field should be presented in this cell.


How Do I Call a Specific Number in a Matrix?

matA = math.matrix([[0,1],[2,3],[4,5]]);
matA1_1 = matA.get([1,1]);

the second line would get the row 1, column 1 element


Formatting in the Matrix Editor

It is possible to do fine tuning of the display format of matrices. In this way, it is also possible to create matrix problems that do not appear to be using matrices whatsoever.

Prompt Formatting

Click on the button labelled "Prompt" to adjust the prompt behavior.

Warning: These features can sometimes be unpredictable. Before assigning problems to students, make sure to test out problems on a test assignment.

As an example, here is a problem that uses a Vandermonde matrix to fit a quadratic function to three randomly generated points. 218994

In this case, each coefficient blank simply points to its correct spot in the answer matrix (In this case the matrix is packed with a different order than normal).

f(x) = #textf2d=[0,0]#x2 +#textf2d=[0,1]#x+#textf2d=[1,0]#


If the input fields are not showing up on the same line, when you want them to, surround everything that should be on the same line with:


<span class="form-inline"> --Stuff that should be on the same line-- </span>