(a) Is the matrix \(A\) diagonalizable? [Enter ${LQ}Y${RQ} or ${LQ}N${RQ},
without the quotation marks.] \{ $mp -> ans_rule (3) \}
$PAR
(b) If your answer to part (a) was Y, find matrices \(P\) and \(D\) such that
\(D\) is a diagonal matrix and \(A = PDP^{-1}\); enter them below.$BR
\(P =~\)\{ $mp -> ans_array \} $BR and
\(D =~\)\{ $mp -> ans_array \}
$PAR
(c) If your answer to part (a) was N, the reason is because the dimension
of the eigenspace of \(\lambda =~\)\{ $mp -> ans_rule (5) \} is not equal
to its multiplicity.
As you can see, this is best done using a multiple answer object. Now, if the answer is N, I want the matrices to be optional. However ... and this is what I'm having problems with ... if the answer is N, and the student enters only N and the correct value of lambda, then the answer is counted wrong. (If the student enters an N, the value of lambda, and at least one entry into the spots for D and P, then the problem works.) My checker looks like:
Context()->parens->set("[" => {formMatrix => 1});
$mp = MultiAnswer ($YN, $P, $D, $L0) -> with (
singleResult => 1,
checkTypes => 0,
allowBlankAnswers => 1,
checker => sub {
my ($correct, $student, $self) = @_; # get the parameters
my ($corrYN, $corrP, $corrD, $corrL0) = @{$correct};
my ($stuYN, $stuP, $stuD, $stuL0) = @{$student};
if (! Value::classMatch ($stuYN, 'String')) { return 0; }
if ($corrYN ne $stuYN) { return 0; }
if (! Value::classMatch ($stuP, 'Matrix'))
{ $stuL0 = $stuP; $stuP = Matrix ([[0]]); $stuD = Matrix ([[0]]); }
my $i, $j;
if ($corrYN eq 'Y') {
if (! Value::classMatch ($stuP, 'Matrix')) { return 0; }
if (! Value::classMatch ($stuD, 'Matrix')) { return 0; }
for ($i = 1; $i <= 4; $i++) { for ($j = 1; $j <= 4; $j++) {
if (($i != $j) && ($stuD -> element ($i, $j) != 0)) { return 0; }
}}
if ($stuP -> det == 0) { return 0; }
my $corrA = Matrix ($corrP * $corrD * $corrP -> inverse);
my $stuA = Matrix ($stuP * $stuD * $stuP -> inverse);
return (Matrix ($corrA - $stuA) -> isZero);
}
else { return ($stuL0 == $corrL0); }
}
);
It seems that my error is coming from the fact that, if you try to create a matrix with no entries, an error is produced, which causes the answer to be counted as incorrect. Is there a way to bypass that error, short of recoding Matrix.pm in WeBWorK?
[Sorry about the formatting. WWforums's fault.]