ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 09 Mar 2012 03:48:57 -06003d plot ignoring imaginary parthttps://ask.sagemath.org/question/8776/3d-plot-ignoring-imaginary-part/Is there any possibility to have a 3d plot done in a way that if the expression to be plotted returns a complex number, this is not plotted. In particular I'm referring to this feature in Matlab: when you try to plot in 3d an expression which in his domain has both real and complex values, it returns the plot only when the values are real. In addition Matlab prints a Warning: "Imaginary parts of complex X, Y, and/or Z arguments ignored".
Thanks! (tell me if it's not clear, I'll explain better...)Wed, 07 Mar 2012 05:33:08 -0600https://ask.sagemath.org/question/8776/3d-plot-ignoring-imaginary-part/Answer by Michele for <p>Is there any possibility to have a 3d plot done in a way that if the expression to be plotted returns a complex number, this is not plotted. In particular I'm referring to this feature in Matlab: when you try to plot in 3d an expression which in his domain has both real and complex values, it returns the plot only when the values are real. In addition Matlab prints a Warning: "Imaginary parts of complex X, Y, and/or Z arguments ignored".</p>
<p>Thanks! (tell me if it's not clear, I'll explain better...)</p>
https://ask.sagemath.org/question/8776/3d-plot-ignoring-imaginary-part/?answer=13344#post-id-13344I just get to a solution by myself...
My problem was the impossibility to plot because of numerical errors that turns my (expected) real values into complex numbers with an imaginary part extremely small.
I used the fantastic function "**list_plot3d**". For example:
var ('x y')
f = sqrt(1+x+y)
list = []
for n in [-2.0,-1.9..,2.]:
for m in [-2.0,-1.9..,2.]:
list.append((n,m,real(f(x=n,y=m))))
show(list_plot3d(list))
It's not difficult to modify the above code if one wants to really ignore complex numbers while plotting (that is indeed what Matlab automatically does).Fri, 09 Mar 2012 03:48:57 -0600https://ask.sagemath.org/question/8776/3d-plot-ignoring-imaginary-part/?answer=13344#post-id-13344