The basic mismatch is that Sage/python evaluates e-5 as 10^(-5) while as

for WeBWorK e is the base of natural logarithms. In WeBWorK E-5 is equivalent to 10^(-5).

The easiest solution is:

$result = AskSage($SageCode1,{

accepted_tos=>true,

debug=>0,

});

$result->{webwork}->{Text2}=~s/e/E/g;

$result->{webwork}->{Text3}=~s/e/E/g;

The last two lines replace all of the e's in the string with E. This simple replacement might not work for all types of answers but it will work with this one since the answers from Sage look like:

0.40824829046386296*I*sqrt(3) + 2.22044604925031e-16

You can also use

ANS($Text1->cmp());

ANS($Text2->cmp());

ANS($Text3->cmp());

ANS(Compute($Text2)->cmp());

ANS(Compute($Text3)->cmp());

To force the last two answers to print simply as 0.71i instead of 0.41*I*sqrt(3.00)+0.

This looks at the string created by $Text2 and then makes a new MathObject from that.

Your method of multiplying by 1 works just as well. The important part is that you

changed the context of the format so that only 2 digits are printed. This only changes the formatting of printed version of the correct answer -- so the answer with the square root will be accepted as will the answer 0.70711i but the answer 0.71i does not have enough precision to be accepted. I'd change the format to print 5 figures of accuracy.

You are currently using guest access (Log in)