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

edit retag close merge delete

Sort by » oldest newest most voted

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

more