Ask Your Question

Why region_plot dont work with absolute value of complex numbers?

asked 2016-10-19 21:07:09 +0200

Masacroso gravatar image

Im trying to plot something like

region_plot([x*abs(x+y*I)-cos(y) <= 5, y^2+e^x<=3],(x,-5,5), (y,-5,5),incol='lightblue',bordercol='blue')

but I get an errorType because the imaginary unit. I dont know how to fix it, any help would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-19 23:05:39 +0200

One way to fix this is to replace abs(x+I*y) with sqrt(x^2+y^2).

Sage plotting routines use native Python type float under the hood for domain variables, while input functions are of the symbolic Sage type Expression. The two don't always mix well for plotting, especially when complex variables are involved.

Another way around the problem is to put lambda x,y: in front of the function containing the complex unit to force evaluation as a Python callable.

edit flag offensive delete link more


Excellent answer - and maybe we need to (finally) fix that. Are there some open tickets about this?

kcrisman gravatar imagekcrisman ( 2016-10-20 03:10:51 +0200 )edit

Thank you very much Paul for this great teaching. But after I read you I need to add an important question, where I can learn how work the structure of SAGE? I mean, you said that some functions use the arguments as an element float, and others are symbolic, if I understood correctly. Then, how can I know all the different type of variables that use SAGE to know what I can do and what I need to do to make that something works?

Masacroso gravatar imageMasacroso ( 2016-10-20 06:46:49 +0200 )edit

Masacroso, I don't know of a single good reference for general types available in Sage. I only know about the float issue in plots because of bugs I've been working on over the summer.

You can always test the type of any expression by evaluating type( expression ). That will show you the entire class parentage of the expression, with its type at the end.

Here's a couple links that might help:

The second is particularly worth reading to save frustration when plots don't work as expected. It led me to post my own question here about native Python functions:

paulmasson gravatar imagepaulmasson ( 2016-10-21 04:09:01 +0200 )edit

Karl-Dieter, I haven't seen any tickets yet addressing this issue. I tried a simple fix today where I though it most effective but it was only partially successful. I suspect that fixing this problem completely will require some changes to fast_float as well as the fast-callable coercion process.

paulmasson gravatar imagepaulmasson ( 2016-10-21 04:12:16 +0200 )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


Asked: 2016-10-19 21:07:09 +0200

Seen: 316 times

Last updated: Oct 19 '16