## 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();
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"PGunion.pl",
);

TEXT(beginproblem());

Context("Complex");
$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) > 4: Pe_real = real(Root) Pe_imag= imag(Root) elif abs(Root) >4: Pe_real = real(Root) Pe_imag= imag(Root) elif abs(Root) >4: Pe_real = real(Root) Pe_imag= imag(Root) else : Pe_real = real(Root) Pe_imag= imag(Root) 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);
$$poles =$$ \{ ans_rule(20)\} (Enter answer as comma separated list)
$showPartialCorrectAnswers = 1; ANS($poles -> cmp(ordered=>0));     # list of two elements