WeBWorK Problems

Math Objects and multi answer

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:

  "PGstandard.pl",     # Standard macros for PG language



$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;


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.


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


 ANS( $multians->cmp( ) );


When I enter the correct answer  the message given is:

Can't convert '' to a Matrix

 Any suggestions?

In reply to David Stowell

Re: Math Objects and multi answer

by Davide Cervone -
The problem is in your custom checker. There is no value for the variable $A, so when you multiply it by the matrix $Pstu, it acts like a blank string, and MathObjects tries to convert that to a Matrix, which produces the error you are seeing. Perhaps you meant to use $D there instead (since the statement of the problem used \(A = $D\)?