I was interested in including the problem Library/NAU/setLinearAlgebra/span.pg in a PreTeXt book, but it doesn't give valid PreTeXt XML.
So I decided I would try to re-write it using PGML. This was mostly successful, in that the problem still seems to work, and I now get valild PTX.
But the question uses a custom answer checker for the matrices to be entered, and the recommended syntax (put a * between the answer blank and the answer) does not produce an answer array for me.
My attempt at modifying this question is below.
(Related question: this problem uses a rank.pl macro that is not part of PG. When I make a local copy, is there a way to make sure this macro gets included? The only way I was able to figure out was to SSH into the server, browse through the OPL to find the file, save it to my computer, and then upload to the macros folder in my course. But if I was the server admin I wouldn't have been able to do this.)
New source:
## DBsubject(Linear algebra)
## DBchapter(Abstract vector spaces)
## DBsection(Span)
## Date(10/5/2013)
## Institution(NAU)
## Author(Nandor Sieben)
## Level(2)
## MO(1)
## KEYWORDS('linear algebra','span')
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"AnswerFormatHelp.pl",
"MatrixReduce.pl",
"rank.pl",
"PGcourse.pl",
"PGML.pl"
);
$showPartialCorrectAnswers = 1;
TEXT(beginproblem());
Context("Fraction");
Context() -> parens -> set ("[" => {formMatrix => 1});
{
$a11= random(-5,5,1);
$a12= random(-5,5,1);
$a22= random(-5,5,1);
$b11= random(-5,5,1);
$b12= random(-5,5,1);
$b22= random(-5,5,1);
Context() -> parens -> set ("[" => {formMatrix => 1});
$A = Matrix([[$a11,$a12],[$a12,$a22]]);
$B = Matrix([[$b11,$b12],[$b12,$b22]]);
redo if(rank(Matrix([[$a11,$a12,$a22],[$b11,$b12,$b22],[0,0,0]]))<2);
}
$answer = $A+$B;
$answer = $A-$B if (rank($answer) == 0);
{
$c1 = Compute(random(-2,2,1));
$c2 = Compute(random(-2,2,1));
$c3 = Compute(1);
Context() -> parens -> set ("[" => {formMatrix => 1});
$answer2=Matrix([[$c1,$c3],[$c3,$c2]]);
redo if (rank(Matrix([$a11,$a12,$a22],[$b11,$b12,$b22],
[$answer2->element(1,1),$answer2->element(1,2),$answer2->element(2,2)])) == 2);
}
$A1 = $answer->cmp(
checker => sub {
my ($correct, $student, $ansHash) = @_;
if ( ! $student->is_symmetric )
{ return 0; }
if ( rank(Matrix($student)) == 0 )
{ return 0; }
if (rank(Matrix([$a11,$a12,$a22],[$b11,$b12,$b22],
[$student->element(1,1),$student->element(1,2),$student->element(2,2)])) == 2) {
return 1;
}
return 0;
}
);
$A2 = $answer2->cmp(
checker => sub {
my ($correct, $student, $ansHash) = @_;
if ( ! $student->is_symmetric )
{ return 0; }
if (rank(Matrix([$a11,$a12,$a22],[$b11,$b12,$b22],
[$student->element(1,1),$student->element(1,2),$student->element(2,2)]))==3) {
return 1;
}
return 0;
}
);
Context()->texStrings;
BEGIN_PGML
Let [`V`] be the vector space of symmetric [`2\times 2`] matrices and
[`W`] be the subspace
[```W=\operatorname{span} \left\{ [$A],[$B] \right\} .```]
a. Find a nonzero element [`X`] in [` W `].
[` X =`] [__________]*{$A1}
b. Find an element [`Y`] in [` V `] that is not in [` W `].
[` Y = `] [__________]*{$A2}
END_PGML
ENDDOCUMENT();