WeBWorK Problems

Complex number from .roots() in Sage cannot be recognized as a number

Complex number from .roots() in Sage cannot be recognized as a number

by Boxuan Zhong -
Number of replies: 0
I want to use .roots() function in Sage to compute complex roots. However, webwork cannot recognize complex roots but only real roots. And in Sage Cell Server, if I want to compute the complex roots, it will time out but if I just want to compute real roots, it works fine. Is computing complex roots a different function? Thanks a lot for your help!

DOCUMENT(); 
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGcourse.pl",
"PGunion.pl",
);

TEXT(beginproblem());

Context("Complex");
Context()->constants->add( I=>{value => i} );

$SageCode1=<<END;
I = ComplexDoubleElement(0,1)
var('x')
#f1= (x+2)*(x+4)*(x+5)*(x+6)# this works, everything works well
f1= (x+2)*(x+4)*(x+5)*(x+6) + 36*(x*x-2*x+2)# this does not work, no thing will show in the answer
Root = f1.roots()
if abs(Root[0][0]) > 4: 
   Pe_real = real(Root[0][0])
   Pe_imag= imag(Root[0][0])
elif abs(Root[1][0]) >4:  
   Pe_real = real(Root[1][0])
   Pe_imag= imag(Root[1][0])
elif abs(Root[2][0]) >4:  
   Pe_real = real(Root[2][0])
   Pe_imag= imag(Root[2][0])
else :  
   Pe_real = real(Root[3][0])
   Pe_imag= imag(Root[3][0])

WEBWORK['poles1']= Pe_real + Pe_imag*I
WEBWORK['poles2']= Pe_real - Pe_imag*I
END

$result= AskSage($SageCode1,{
       accepted_tos=>true, 
});

$result->{webwork}->{poles1}=~s/e/E/g;
$result->{webwork}->{poles2}=~s/e/E/g;
$poles1= Compute($result->{webwork}->{poles1});
$poles2= Compute($result->{webwork}->{poles2});
$poles = List($poles1,$poles2);

Context()->texStrings;
BEGIN_TEXT
\( poles = \) \{ ans_rule(20)\} (Enter answer as comma separated list)

END_TEXT
Context()->normalStrings;
$showPartialCorrectAnswers = 1;
ANS( $poles -> cmp(ordered=>0));     # list of two elements
ENDDOCUMENT();