For the below example code : p_minZeta will be computed to be -1 + 0.707*I
Then Text2 = p_minZeta+1 should equal 0.707*I;
However, p_minZeta actually equals i*0.408248*sqrt(3) + 2.22045*exp(1) -16 in the example code instead of 0.707*I.
My understanding is : due to calculated error, "0" becomes 2.22045*e^(-16) in Sage but webwork mistakenly converts it to be 2.22045*exp(1) -16, which is -9.96. Is that correct?How can we solve this problem?
##############################
# Initialization
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"parserFunction.pl",
"answerHints.pl",
"PGcourse.pl",
);
TEXT(beginproblem());
###########################
# Setup
Context("Complex");
Context()->constants->add( I=>{value => i} );
$z1=-2;
$z2=-3;
$p1 = 0;
$p2 = -1;
$pi = pi;
$SageCode1=<<END;
####The code below is to generate p_minZeta = -1 + 0.707*I
p1 = $p1;
p2 = $p2;
z1 = $z1;
z2 = $z2;
var('x')
f= (x-p1)*(x-p2)*(x-0.5*(z1+z2))-(x-z1)*(x-z2)*(x-0.5*(p1+p2))
Root = f.roots()
xc = 0.5*(Root[0][0]+Root[1][0])
R = 0.5*(Root[1][0] - Root[0][0])
d = sqrt(xc*xc -R*R)
a = atan2(R,d)
I = ComplexDoubleElement(0,1)
p_minZeta = -cos(a)*d + sin(a)*d*I;
####The code above is to generate p_minZeta = -1 + 0.707*I
#p_minZeta = -1 + 0.707*I;# if I do this line, the answer will be correct.
Text1 = p_minZeta
Text2 = p_minZeta+1
Text3 = abs(p_minZeta+1)
WEBWORK['Text1']=Text1
WEBWORK['Text2']=Text2
WEBWORK['Text3']=Text3
END
$result = AskSage($SageCode1,{
accepted_tos=>true,
debug=>0,
});
Context()->{format}{number} = "%.2f";
#################################
$Text1= Compute($result->{webwork}->{Text1});
$Text2= Compute($result->{webwork}->{Text2});
$Text3= Compute($result->{webwork}->{Text3});
$Text4 = (1+0*i)*$Text2; # in order to change formula to numbers
$Text5 = (1+0*i)*$Text3; # in order to change formula to numbers
TEXT(pretty_print($result->{webwork}));
#############################
# Main text
Context()->texStrings;
BEGIN_TEXT
$BR
\( Text1 = \) \{ ans_rule(10)\} , \(Text2= \) \{ ans_rule(10)\} , \(Text3= \) \{ ans_rule(10)\}, \(Text4= \) \{ ans_rule(10)\} , \(Text5= \) \{ ans_rule(10)\}
$PAR
END_TEXT
Context()->normalStrings;
##############################
# Answer evaluation
$showPartialCorrectAnswers = 1;
ANS($Text1->cmp());
ANS($Text2->cmp());
ANS($Text3->cmp());
ANS($Text4->cmp());
ANS($Text5->cmp());
ENDDOCUMENT();