WeBWorK Main Forum

getting started with complex eigenvectors

getting started with complex eigenvectors

by Greg Mayer -
Number of replies: 0
I'd like to have a question for a linear algebra course I'm working on, where students enter complex eigenvectors for a 2x2 anti-symmetric matrix with integer values. I'm not sure how to set up the answer checker. Can anyone tell me what I'm doing wrong? The code below gives me the error "There is a syntax error in your answer." when I enter "i" or sqrt(-1) into the entries of the vectors. The code I have so far is below.



DOCUMENT();

loadMacros(
"PGstandard.pl",
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGgraphmacros.pl",
"PGmatrixmacros.pl", 
"PGmorematrixmacros.pl",
"PGnumericalmacros.pl",
"PGauxiliaryFunctions.pl",
"MathObjects.pl",
"PGcourse.pl",
"MatrixCheckers.pl"
);

TEXT(beginproblem());

Context("Complex");
$i = Complex(0,1); 
$one = Complex(1,0);

# define A = 2x2 random integer anti-symmetric matrix given to students
  $c1 = random(1,4,1);
  $c2 = random(1,5,1);
  $A = new Matrix(2,2);
  $A->assign(1,1, $c1 );
  $A->assign(1,2, -$c2 );
  $A->assign(2,1, $c2 );
  $A->assign(2,2, $c1 );

# convert to matrix for display
  $AMatrix = Matrix($A); 

Context()->texStrings;
BEGIN_TEXT
The matrix

$BR$BR
\( $AMatrix \)
$BR$BR

has complex eigenvalues   

\{ans_rule(10)\}
\( \pm \)  \{ans_rule(10)\} \(i\).

$BR$BR

The eigenvectors of the matrix are
$BR

\{ mbox(   ans_array(2,1,5), ans_array_extension(2,1,5) ) \}

END_TEXT

Context()->normalStrings;

ANS(Compute("$c1")->cmp);
ANS(Compute("$c2")->cmp);

ANS(basis_cmp([[1,Compute("i")],[1,Compute("-i")]]));

ENDDOCUMENT();