First time here? Check out the FAQ!

Ask Your Question
1

Finding roots of complex functions

asked 14 years ago

David Ferrone gravatar image

updated 10 years ago

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

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 14 years ago

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.

Preview: (hide)
link
1

answered 14 years ago

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.

Preview: (hide)
link

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 ( 14 years ago )

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: 14 years ago

Seen: 1,903 times

Last updated: Mar 13 '11