# Finding roots of complex functions This could be a Maxima question as it relates to find_root, find_minimum_on_interval, etc.

When I try to find the root of a function involving I (complex numbers) I get:

TypeError: float() argument must be a string or a number

For example, find_root(abs(1-exp(I*x)),-1,1).

edit retag close merge delete

Sort by » oldest newest most voted

One way to get around this is to define the real and imaginary parts of the function and find roots of the sum of their squares:

sage: x = var('x')
sage: f = 1 - exp(I*x)
sage: fr = real_part(f)
sage: fi = imag_part(f)
sage: find_root(fr^2 + fi^2, -1, 1)
0.0


Calling full_simplify() on f = abs(1- exp(I*x)) returns a multiply of I which is clearly a real number (if x is a real number), but I don't know how to coax maxima or Sage into converting f into a explicitly real function of a real variable.

more 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.

more

Yeah, this is a long-standing problem, which unfortunately we've never had the energy to sort through in all cases. Help is welcome - there may be more than one ticket about this.