# Graphing Complex Functions 3D (x,y,i axes) Instead Of Color-Coded 2D (x,i) Following this guide to Sage: and using Sage Online produced the following graphs:  It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane.

You can do what I wish using Maple:

edit retag close merge delete

Sort by » oldest newest most voted

One approach would be to use plot3d. For example,

var('x,y')
plot3d(lambda x,y: norm(1/(((x+i*y)-3)*((x+y*i)+2))),(x,-4,4),(y,-4,4))


gives I've not been able to get the coloring that you'd probably like, but this does give the 3d plot rather than the 2d plot you were getting.

more Some approximation :

var('x,y')
cm = colormaps.jet
pi2 = 2 * pi.n()
def f(x, y):
z = x + I * y
return (z-2)/(z+3)**2
def cf(x, y):
return f(x, y).n().arg() / pi2 + 0.5
plot3d(lambda x, y: f(x, y).n().abs(), (x,-4,4), (y,-4,4), color=(cf, cm))

more

In the following we

• increase the number of plot points to improve the resolution of the image,
• use RDF and CDF: "real double field", "complex double field" -- floating-point real and complex numbers,
• avoid Sage's "symbolic variables" and "symbolic ring" throughout.

Doing this, the spike however reaches higher and higher values, so it becomes necessary to truncate the z values.

Pick a colormap and define $\tau = 2\pi$.

sage: cm = colormaps.jet
sage: tau = 2 * RDF.pi()


Define f:

sage: def f(x, y):
....:     z = CDF(x, y)
....:     return (z - 2) / (z + 3)**2


Define f_abs (modulus of f):

sage: f_abs = lambda x, y: f(x, y).abs()


Define truncation:

sage: trunc = lambda x, t: x if x.abs() < t else RDF.nan()


Pick a bound to truncate:

sage: zbound = 8


Define f_abs_trunc as f_abs truncated to the chosen bound.

sage: f_abs_trunc = lambda x, y: trunc(f_abs(x, y), zbound)


Define f_arg_color as the coloring for the argument of f:

sage: f_arg_color = lambda x, y: f(x, y).arg() / tau + RDF(0.5)


Compute the plot:

sage: p = plot3d(f_abs_trunc, (-4, 4), (-4, 4), color=(f_arg_color, cm), plot_points=200)


Show the plot (choose viewer='threejs' or viewer='jmol' or viewer='tachyon'):

sage: p.show(viewer='threejs')


Increasing plot_points further makes a nicer plot while also increasing the time to show the plot. Try for example plot_points=400 or even plot_points=800.

One can also increase zbound to see more of the spike (try for example zbound=1e2 or zbound=2e5). Or plot f_abs instead of f_abs_trunc to avoid truncation altogether.

more