contextCopmlesExtras.pl - Add conjugation to Complex contexts, and transpose, conjugate transpose, trace, and determinant to Complex-Matrix context.
The contextComplexExtras.pl file adds the ability to include matrix transpose, conjugate transpose, trace, and determinants in student answers in the Complex-Matrix context, and adds conjugation to all Complex contexts.
Conjugation is represented by ~
, as in ~z
or ~M
to conjugate a complex number or complex matrix. This can be used in both PG code as well as student answers. The transpose is represented by ^T
, as in M^T
, in student answers or parsed strings. The conjugate transpose is ^*
, as in M^*
, and is equivalent to ~M^T
. The trace is given as tr(M)
, and the determinant by det(M)
. Thus you can do things like:
loadMacros("contextComplexExtras.pl");
Context("Complex-Matrix");
Context()->constants->add(
A => Matrix([[pi+i,i/pi**2],[1+sqrt[2]*i,ln(pi)-2*i]]), # an arbitrary matrix with no special properties
);
$F = Formula("det(~A) + tr(A^*)");
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;
$Mc = ~$M;
$Ms = ~($M->transpose);
Note that the contextComplexExtras.pl file modifies the Complex, Complex-Point, Complex-Vector, and Complex-Matrix contexts, so be sure to load it before you set the Context.