## WeBWorK Problems

### Math Objects and multi answer

by David Stowell -
Number of replies: 1
I'm working on a problem with matrix a factorizations. A simplified version of the problem is to diagonalize a given matrix. In the problem, the student is given an n xn Matrix A, and is to provide a diagonal matrix D and an invertible matrix P such that A=PDP^(-1). As I understand it, I want to use MultiAnswer because I really need to use both answers to check  if the result is correct. Here is code for a simplified version:

DOCUMENT();
"PGstandard.pl",     # Standard macros for PG language
"MathObjects.pl",
);

TEXT(beginproblem());

Context("Matrix");

do{
$e1 = non_zero_random(-5,5);$e2 = non_zero_random(-5,5);
} while ($e1 ==$e2);

$D = Matrix([[$e1,0],[0,$e2]]);$Psol = Matrix( [ [ 1,0],  [0,1 ]   ]     );
$Dsol = Matrix( [ [$e1,0],  [0,$e2 ] ] );$multians = MultiAnswer($Dsol,$Psol)->with(singleResult=>1,
checker => sub{
my($correct,$student, $self) = @_; my ($Dstu, $Pstu) = @{$student};
my @c = @{$correct}; return$A*$Pstu ==$Pstu*$Dstu; } ); Context() ->texStrings; BEGIN_TEXT Let $$A=D$$. Find an invertible matrix $$P$$ and a diagonal $$D$$ such that $$PDP^{-1} = A$$. The matrix $$D$$ should have the eigenvalues of $$A$$ on its diagonal.$BR

$$D$$ =\{$multians ->ans_array(3)\},$$P$$ =\{$multians ->ans_array(3)\}
END_TEXT

Context()->normalStrings;