Jump to: Site Navigation

*contextMatrixExtras.pl* - Add transpose, trace, and determinant to Matrix context

The *contextMatrixExtras.pl* file adds the ability to include matrix transpose, trace, and determinants in student answers. The transpose is represented by `^T`

, as in `M^T`

, in student answers or parsed strings. The trace is given as `tr(M)`

, and the determinant by `det(M)`

. Thus you can do things like:

```
loadMacros("contextMatrixExtras.pl");
Context("Matrix");
Context()->constants->add(
A => Matrix([[pi,1/pi**2],[sqrt[2],ln(pi)]]), # an arbitrary matrix with no special properties
);
$F = Formula("det(A) + tr(A^T)");
Context()->texStrings;
BEGIN_TEXT
\($F\) = \{ans_rule(20)\}
END_TEXT
Context()->normalStrings;
ANS($F->cmp);
```

You can also use the `trace`

, `det`

, and `transpose`

methods of a Matrix object to compute these in PG code.

```
loadMacros("contextMatrixExtras.pl");
Context("Matrix");
$M = Matrix([[1,2],[3,4]]);
$Mt = $M->transpose;
$d = $M->det;
$tr = $M->trace;
```

Note that the *contextMatrixExtras.pl* file modifies the Matrix context, so be sure to load it before you set the Context.