Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are a couple of ways to get around this:

sage: find_root(lambda x: RR(abs(1-exp(I*x))),-1,1)
5.5511151231257827e-17

sage: find_root(simplify(abs(1-exp(I*x))),-1,1)
5.5511151231257827e-17

Under the hood this is becoming sqrt((cos(x) - 1)^2 + sin(x)^2).

But I think this should work:

sage: RR(abs(exp(x*I)).subs(x=2))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[...]
/Applications/sage/local/lib/python2.6/site-packages/sage/rings/number_field/number_field_element.so in     sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (sage/rings/number_field/number_field_element.cpp:8541)()

TypeError: cannot convert 2*I to real number

You shouldn't need each expression operand to be real to convert to a real.