Ask Your Question
0

Unable to coerce to real

asked 2014-11-13 18:08:45 +0100

foliot gravatar image

updated 2014-11-14 23:51:43 +0100

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-11-13 18:54:45 +0100

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

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 ( 2014-11-13 19:50:09 +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

1 follower

Stats

Asked: 2014-11-13 18:08:45 +0100

Seen: 2,241 times

Last updated: Nov 13 '14