# Graphing Compex Functions 3D (x,y,i axes) Instead Of Color-Coded (SAGE).

Following this guide to Sage: and using Sage Online produced the following graphs:

Graphing $\frac{1}{1-z}$ that way yeilds:

Graphing $\frac{1}{1-z^2}$ that way yields:

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.

• Does it have to be done in Sage? – Amzoti Jul 20 '13 at 23:36
• @Amzoti It would be much preferred if it were to use a free software program such as octave or SAGE. – User3910 Jul 20 '13 at 23:49
• You might want to try another free CAS like Maxima (has online version too) or others at: en.wikipedia.org/wiki/List_of_computer_algebra_systems – Amzoti Jul 20 '13 at 23:51
• @Amzoti Maxima is a part of Sage. Actually, I think it even internally calls Maxima for formal computation. – Pece Aug 10 '13 at 11:22
• @Pece: Many pieces make up SAGE, but Maxima is just one of the engines, there are many others. You call the one you want for the specific function you want. Maxima is a standalone program and does not need SAGE. Regards – Amzoti Aug 10 '13 at 12:01

You can understand complex functions better by expanding in terms of real variables. For example, let's take a look at the function $$\frac{1}{1+z^2}$$ by letting $z=x+iy$, where $x$ and $y$ are real. Then $$\frac{1}{1+(x+iy)^2}=\frac{1}{1+x^2-y^2+2xyi}=\frac{1+x^2-y^2-2xyi}{(1+x^2-y^2)^2+4x^2y^2},$$ where we have multiplied numerator and denominator of the middle expression by the complex conjugate of the denominator to make the denominator purely real. You can then separate to obtain $$\frac{1}{1+z^2}=\frac{1+x^2-y^2}{(1+x^2-y^2)^2+4x^2y^2}-i\frac{2xy}{(1+x^2-y^2)^2+4x^2y^2}.$$

Notice how the complex function is broken into real and imaginary components.

$$\text{Re}\left(\frac{1}{1+z^2}\right)=\frac{1+x^2-y^2}{(1+x^2-y^2)^2+4x^2y^2}$$

$$\text{Im}\left(\frac{1}{1+z^2}\right)=\frac{-2xy}{(1+x^2-y^2)^2+4x^2y^2}$$

ADDED BY OTHER USER: AntonioVargas shared the following plot from Mathematica of $\text{Re}(1/(1+z^2))$ colored according to $\text{Im}(1/(1+z^2))$:

However it is just as easy to graph it in Wolfram Alpha

Also the 3D plot of the imaginary component.

This is the codes in which you can visualize the complex functions in Maple's environment:

  [> with(plots):
[> f := z-> 1/(1-z):
g:=z-> 1/(1-z^2):
[> complexplot3d(f, -2-2*I .. 2+2*I);
complexplot3d(g, -2-2*I .. 2+2*I);


• Very nice graphs! I'm convinced the NSF or something should fund an open-source version like Sage... ok I just don't want to pay for Maple... – User3910 Jul 20 '13 at 23:40
• I agree, awesome graphs: and the colors of a rainbow! – Namaste Jul 21 '13 at 0:11
• @amWhy: Thanks Amy. – mrs Jul 21 '13 at 6:55
• @BabakS.: Ditto, nice graphics! +1 – Amzoti Jul 21 '13 at 12:44

To the best of my knowledge, Sage at present does not offer 3d plots with color determined by a function. (But I'm not a Sage expert like those who inhabit ask Sage Q&A site.) As Babak S. pointed out, Maple does the job, for those who have access to it. However, I think the following picture (made with a different Maple command) looks nicer:

f:=1/(1-(x+I*y)^2):
plot3d(abs(f), x=-3..3, y=-3..3, color=argument(f), grid=[50,50]);

• Thanks for the "ask Sage" link. – User3910 Jul 20 '13 at 23:44
• Asked on the "ask Sage" site: – User3910 Jul 20 '13 at 23:50

I wrote a little something in three.js/webgl to do this.

It allows you to choose how to map your 4 available complex axes to X,Y,Z and color gradient.

It is using math.js, so to express formulas you need to call the appropriate math.js functions which isn't so elegant, but it works. E.g. for

$$\frac{1}{1+z^2}$$

you write:

g=divide(1,add(1,pow(f,2)))


Free, no install of anything required. Sharable. Just a hobby project, but might be useful. Some other examples here.

The simplest way is to merely replace z with "x+iy" and hit enter in wolfram alpha:

$$1/(1+(x+iy)^2)$$

or for 1/(1-(x+iy)^2)

1/(1-x^2+y^2-2xyi) times