Attached is the problem P3subspaceBasis.pg, in the OPL at Library/NAU/setLinearAlgebra/P3subspaceBasis.pg.
I'm attempting to edit it so that it works as both a WeBWorK problem, and as a textbook problem (via PreTeXt). It works all right as-is, but it does not look great in print. In a book, you would like to just have the statement of the problem ("Find a basis of the subspace..."). You generally do not want to see the extra line with p(x) = ________ q(x) = __________
There's a mechanism in PreTeXt wherein a paragraph that contains only an answer blank is ignored, unless the WeBWorK problem is activated. So my goal is to have a single answer blank accepting a list for the answer, rather than a pair of blanks using MultiAnswer.
My version below works if the answer is the obvious one (for the seed in the problem editor, I get the basis {x, x^2+5}), and it works in either order. But if I replace one of the basis vectors by a multiple of that vector, the answer is marked wrong. This doesn't happen using the existing MultiAnswer: it will accept both x and 2x.
Is there a way to replace MultiAnswer with List and preserve the custom checking present in this problem? Here is my attempt at updating the problem. (I also converted from PG to PGML.)
## DBsubject(Linear algebra)
## DBchapter(Abstract vector spaces)
## DBsection(Basis and dimension)
## Date(10/11/2013)
## Institution(NAU)
## Author(Nandor Sieben)
## Level(2)
## MO(1)
## KEYWORDS('linear algebra','span')
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"MatrixReduce.pl",
"rank.pl",
"PGcourse.pl",
"PGML.pl",
"PCCmacros.pl"
);
$showPartialCorrectAnswers = 1;
$l=non_zero_random(-9,9,1);
$p1=Formula("2*$l-1+x^2")->reduce;
$p2=Formula("x")->reduce;
$basis = List($p1, $p2)->with(
singleResult => 1,
checker => sub {
my ( $correct, $student, $self ) = @_;
my ($s1,$s2) = @{$student};
my @c = @{$correct};
my $s1D=$s1->D('x');
my $s2D=$s2->D('x');
my $s1DD=$s1D->D('x');
my $s2DD=$s2D->D('x');
if ($s1D->eval(x=>$l) != $s1->eval(x=>1)) {
$self->setMessage(1,"Not in the subspace.");
return 0
}
if ($s2D->eval(x=>$l) != $s2->eval(x=>1)) {
$self->setMessage(2,"Not in the subspace.");
return 0
}
my $s1DDD=$s1DD->D('x');
my $s2DDD=$s2DD->D('x');
if ($s1DDD != Formula("0")) {
$self->setMessage(1,"Not in the subspace.");
return 0
}
if ($s2DDD != Formula("0")) {
$self->setMessage(2,"Not in the subspace.");
return 0
}
my $a1=$s1->eval(x=>0);
my $b1=$s1D->eval(x=>0);
my $c1=$s1DD->eval(x=>0)/2;
my $a2=$s2->eval(x=>0);
my $b2=$s2D->eval(x=>0);
my $c2=$s2DD->eval(x=>0)/2;
if (rank(Matrix([$a1,$b1,$c1],[$a2,$b2,$c2])) ==2) {
return 1;
}
$self->setMessage(1,"Not independent.");
$self->setMessage(2,"Not independent.");
return 0;
}
);
BEGIN_PGML
Find a basis [` \lbrace p(x), q(x) \rbrace `] for the vector space
[`\lbrace f(x)\in P_2(\mathbb{R}) \mid f'([$l])=f(1) \rbrace`]
where [`P_2(\mathbb{R})`] is the vector space of polynomials in [`x`] with degree less than or equal to 2.
[__________]{$basis}
[@KeyboardInstructions('Enter your answer as a comma-separated list of polynomials.')@]**
END_PGML
ENDDOCUMENT();