Ask Your Question
1

Finding roots of complex functions

asked 2011-03-13 16:16:00 +0100

David Ferrone gravatar image

updated 2015-01-14 16:22:25 +0100

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
2

answered 2011-03-13 17:34:19 +0100

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

edit flag offensive delete link more
1

answered 2011-03-13 20:03:59 +0100

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

edit flag offensive delete link more

Comments

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 08:24:50 +0100 )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

Stats

Asked: 2011-03-13 16:16:00 +0100

Seen: 1,815 times

Last updated: Mar 13 '11