Ask Your Question

Finding roots of complex functions

asked 2011-03-13 10:16:00 -0600

David Ferrone gravatar image

updated 2015-01-14 09:22:25 -0600

FrédéricC gravatar image

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 flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2011-03-13 11:34:19 -0600

benjaminfjones gravatar image

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)

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.

edit flag offensive delete link more

answered 2011-03-13 14:03:59 -0600

DSM gravatar image

There are a couple of ways to get around this:

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

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

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

edit flag offensive delete link 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.

kcrisman gravatar imagekcrisman ( 2011-03-14 02:24:50 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-03-13 10:16:00 -0600

Seen: 909 times

Last updated: Mar 13 '11