Sorry, this content is no longer available

Ask Your Question
0

Unable to coerce to real

asked 10 years ago

foliot gravatar image

updated 10 years ago

vdelecroix gravatar image

I'm having trouble with the find_local_minimum and find_local_maximum functions on the absolute value of a complex function. For instance, the following code is logical and works mathematically, but not in Sage:

x = var('x')
find_local_maximum(abs(i*x), 1000, 3000)

But alas, I get the error:

TypeError: unable to coerce to a real number

I've also tried adding an explicit conversion to real (desperate times):

x = var('x')
find_local_maximum(abs(i*x).real(), 1000, 3000)

This gave the same error.

How do I get around this issue? And is there the possibility that this could be resolved in the Sage codebase? It seems feasible, since the plot function works just fine with the exact same function.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 10 years ago

tmonteil gravatar image

This is clearly a bug. Looking ate the source code, it seems to be related to the fact that Sage tries to transform the smbolic expression abs(i*x) into an object which provides fast floating point evaluation of it:

sage: abs(i*x)._fast_float_()
TypeError: unable to coerce to a real number

A workaround is to provide a python function, not a symbolic expression:

sage: f = lambda x : abs(i*x)
sage: find_local_maximum(f, 1000, 3000)
(2999.999947571147, 2999.999947571147
Preview: (hide)
link

Comments

That works in this case. I have another problem, but I think it deserves a new question, so I'll ask it there.

foliot gravatar imagefoliot ( 10 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

1 follower

Stats

Asked: 10 years ago

Seen: 2,275 times

Last updated: Nov 13 '14