![]() | 1 | initial version |
This seems to output an AttributeError
, namely 'sage.rings.real_mpfr.RealLiteral' object has no attribute 'real_part'
. Also note that there are some real numbers in the list.
A way to work around this is to convert each element x
to a complex number via CC(x)
, see updated for loop below.
for el in [CC(x) for x in allRootsAPow2]:
if (math.ceil(el.real_part()*10)/10)== 2 and (math.ceil(el.imag_part()*10)/10)== 3 :
show(el)
One other option is to define a number to which you cant to compare ($2+3i$ in your example) and a tolerance (0 from above) and use the modulus of the difference as a metric (here the conversion to CC
seems to be implicit through the subtraction from other
).
other = CC(2+3*i)
tolerance = 0.001
print [x for x in allRootsAPow2 if abs(other-x)<=tolerance]
![]() | 2 | No.2 Revision |
This seems to output an AttributeError
, namely 'sage.rings.real_mpfr.RealLiteral' object has no attribute 'real_part'
. Also note that there are some real numbers in the list.
A way to work around this is to convert each element x
to a complex number via CC(x)
, see updated for for
loop below.
for el in [CC(x) for x in allRootsAPow2]:
if (math.ceil(el.real_part()*10)/10)== 2 and (math.ceil(el.imag_part()*10)/10)== 3 :
show(el)
One other option is to define a number to which you cant want to compare to ($2+3i$ in your example) and a tolerance (0 from above) and use the modulus of the difference as a metric (here the conversion to CC
seems to be implicit through the subtraction from other
).
other = CC(2+3*i)
tolerance = 0.001
print [x for x in allRootsAPow2 if abs(other-x)<=tolerance]