Math 421  •  Fall 2006

Visualizing complex functions

Copyright © 2004–2006 by Murray Eisenberg.  All rights reserved.

This notebook shows how to use David Park's Cardano3 Mathematica add-on application to visualize functions \(TraditionalForm\`f : \ ℂ\  -> \ ℂ\).  Appendix 1 describes how to use, instead, the more limited capabilities provided by the Standard Add-on package Graphics`ComplexMap`.

The functions ComplexPoint, ComplexCurve, ComplexLine, and ComplexCircle from Park's package Cardano3`ComplexGraphics` are used below.  To learn about these functions for creating primitive graphics objects, see notebook IntroComplexGraphics.nb.

Example 1: f(z)  =  (z^2)

Most of this notebook concerns visualizing just the single example f(x)  =   (z^2).  A couple of other examples are treated more briefly below.

Be sure to evaluate the following input cell before proceeding:

f[z_]  :=  (z^2)

Cartesian form: real and imaginary parts u(x,  y) and v(x,  y) of f(x  +  i y)

Here is the formula for the function f in terms of the real part x and the imaginary part y of an input z  =  x  +  i y…

f[x  +  I y]

…and here is that formula after the squaring is done:

Expand[%]

We humans cannot directly visualize the graph
	{z,  
        f(z)  :  z  ∈  ℂ}
of \(TraditionalForm\`f\  : \ ℂ\  -> \ ℂ\).  Why not?  We shall see in a moment.

Form the "real part" u and "imaginary part" v of the function f.  These are the functions u(x,  y) and v(x,  y) for which
 	f(x  +  i y)  =  
        u(x,  y)  +  i v(x,  y)
 when x and y are real.  In Mathematica:

u[x_,  y_]  :=  (x^2)  -  (y^2)
v[x_,  y_]  :=  2 x y

Check that really f(x  +  i y)  =  
        u(x,  y)  +  i v(x,  y):

f[x  +  I y]  ==  
      u[x,  y]  +  I v[x,  y]

Check again, but this time forcing Mathematica to regard variables x and y as real (as you intended):

ComplexExpand[f[x  +  I y]]  ==  
      u[x,  y]  +  I v[x,  y]

Strictly in terms of real and imaginary parts, think of f as follows:

F[x_,  y_]  :=  {u[x,  y],  v[x,  y]}

F[x,  y]

Then \(TraditionalForm\`F\  : \ ℝ\^2\  -> \ ℝ\^2\) so:
	graph(
          F)  =  { (  (x,  y},  
              F(x,  y)  )   :  (x,  
                y)  ∈  ℂ }   
\(TraditionalForm\`\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\(=\)\(\ \ \)\({\ \((\ \ \((x, \ y}\), \ \((\ u(x, \ y), \ 
                  v(x, \ y)\ )\)\ \ )\)\ \  : \ \((x, \ 
                  y)\)\  ∈ \ ℂ\ }\ \  ⊂ \ \ ℝ\^4\)\)\) 
But you can directly visualize the graphs of
	\(TraditionalForm\`u\  : \ ℝ\^2\  -> \ ℝ\) and \(TraditionalForm\`v\  : \ ℝ\^2\  -> \ ℝ\),
which as sets are given by:
	 \(TraditionalForm\`graph(
          u)\  = \ \({\ \ \((x, \ y, \ 
                u(x, \ y)\ )\)\  : \ \((x, \ 
                  y)\)\  ∈ \ ℝ\^2\ }\  = \ \ {\ \ \((x, \ y, \ x\^2\  - \ y\^2\ )\)\  : \ \((x, \ 
                    y)\)\  ∈ \ ℝ\^2\ }\ \  ⊂ \ \ ℝ\^3\)\),
	 \(TraditionalForm\`graph(
          v)\  = \ \({\ \ \((x, \ y, \ 
                v(x, \ y)\ )\)\  : \ \((x, \ 
                  y)\)\  ∈ \ ℝ\^2\ }\  = \ \ {\ \ \((x, \ y, \ \ 2  x\ y\ )\)\  : \ \((x, \ 
                    y)\)\  ∈ \ ℝ\^2\ }\ \ \ \ \ \ \ \ \ \  ⊂ \ \ ℝ\^3\)\)

The graphs of the functions u(x,  y) and v(x,  y) in (ℝ^3) will be drawn below.

Making Mathematica calculate u(x,  y) and v(x,  y)

Above, the functions u and v were created by read off from Expand[ f[x + i y] ] their values, then retyping them in the definitions.  That can be done more directly by using ComplexExpand:

u[x_,  y_]  :=  
      ComplexExpand[
        Re[f[x  +  I y]]]
v[x_,  y_]  :=  
      ComplexExpand[Im[f[x  +  I y]]]

{u[x,  y],  v[x,  y]}

Visualizing graphs of u(x,  y) and v(x,  y)

Here are the graphs of the functions u(x,  y) and v(x,  y) in (ℝ^3), drawn using the built-in Mathematica function Plot3D.  (The option BoxRatios is used so that the scale on the vertical axis would appear to be the same as that on the x- and y-axes).

uVSxy  =  
        Plot3D[u[x,  y],  {x,  -2,  2},  {y,  -2,  2},  
          AxesLabel  ->  {"x",  "y",  "u"},  
          BoxRatios  ->   {1,  1,  0.8}];

vVSxy  =  
        Plot3D[v[x,  y],  {x,  -2,  2},  {y,  -2,  2},  
          AxesLabel  ->  {"x",  "y",  "u"},  
          BoxRatios  ->   {1,  1,  0.8}];

Here are both graphs together

Show[GraphicsArray[{uVSxy,  vVSxy}]];

Click on the preceding two-graph image and then drag graphics "handles" of the image to change its size.  Or, force an image size by including the ImageSize option:

Show[GraphicsArray[{uVSxy,  vVSxy}],  
        ImageSize  ->  72 * 7];

Just as in the case of the Cardano3 function ComplexGraphics, the value for the option ImageSize is specified in printer's points.  So with 72 printer's points to the inch, the specified image size is 7 inches.

Using Cartesian coordinates to visualize f as a mapping \(TraditionalForm\`f\  : \ ℂ\  -> \ ℂ\), that is,  \(TraditionalForm\`f\  : \ ℝ\^2\  -> \ ℝ\^2\)

This section uses David Park's add-on package Cardano3`ComplexGraphics` for visualizing f in terms of Cartesian coordinates.  (See Appendix 1 for information on how to do it—albeit not as nicely—with the built-in add-on package Graphics`ComplexMap`, s.)

Loading the Cardano3 packages

You must load the Cardano3 packages before using them:

Needs["Cardano3`ComplexGraphics`"]
Needs["Cardano3`ComplexRoutines`"]

And to avoid annoying messages about similarly-spelled words, switch off such messages:

Off[General::spell]
Off[General::spell1]

The preceding two input cells have been made  will include initialization cells that automatically evaluate those Needs and Off commands either when you first open the notebook or when you first evalute any input in the notebook.  The same thing is done in most other Math 421 notebooks that use these packages.  If you use these packages in your own notebooks, just copy such initializations to your own and evaluate them.

A basic two-panel plot with a rectangular grid

Here is how f transforms a grid of horizontal and vertical lines in the complex plane:

grid  =  {{{Blue},  {-2,  2,  11},  {-2,  2,  
              11}}};

    
TwoPanelPlot[
{{Identity},  
          CartesianGrid,  {0,  3},  {grid}}, 
{{f},  
          CartesianGrid,  {0,  8},  {grid}}];

You may want to include an ImageSize option in TwoPanelPlot expressions such as the preceding one so as to better fit the drawing to your window size.

Try to figure out just what the lists {0, 3} and {0, 8} in the description of each panel are specifying.  Also try to figure out what the second and third arguments  {-2, 2, 11} and  {-2, 2, 11} of grid are specifying.  For help, you can study the result of evaluating the following two input cells:

?TwoPanelPlot

?CartesianGrid

Labelling the panels with function formulas

To see the two panels labeled with z and (z^2) rather than the function names Identity and f, use "pure functions" instead of the function name symbols.  A pure function is an anonymous functions—a function formed with no name.  The squaring function f being used here may be formed as a pure function using the verbose form
	Function[z, (z^2)]
with a "dummy variable" z.  Or this pure function may be formed using the following special input form:
	(\(TraditionalForm\`#\^2\)&)
There the Slot symbol # takes the place of the dummy variable, and the trailing ampersand & indicates that what comes before is a pure function.  Thus:

Function[z,  (z^2)] [1  +  I]

\(\(#\^2 &\)\ [1\  + \ I]\)

Here are two versions of the same two-panel plot again, but with pure functions used to label each panel.  The first version uses the Function[…, …] form and the second version uses the  #…& form for pure functions; the displays are identical.

grid  =  {{{Blue},  {-2,  2,  11},  {-2,  2,  
              11}}};

    
TwoPanelPlot[
{{Function[z,  z]},  
          CartesianGrid,  {0,  
            3},  {grid}}, 
{{Function[z,  (z^2)]},  
          CartesianGrid,  {0,  8},  {grid}}];

grid  =  {{{Blue},  {-2,  2,  11},  {-2,  2,  
              11}}};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 
            3}, \ {grid}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grid}}];\)\)

Using multiply-colored grids

So that you can distinguish the image of the horizontal segments in the grid from the images of the vertical segments in the grid, you may use different colors (or gray scale, or thickness, or dashing treatment, etc.) for the horizontal and vertical segments.  The trick is to create two grids, the first with no horizontal lines and the second with no vertical lines.  For example:

grids = {{{MediumBlue}, {-2,  2,  11}, {-2,  2, 
              0}}, {{AbsoluteDashing[{5}], VenetianRed}, {-2 , 2, 
              0}, {-2,  2, 11}}};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 
            3}, \ {grids}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grids}}];\)\)

Highlighting points or line segments

It's easy to highlight some particular points or line segments and to see their images in the two-panel polar grid plot.  The next TwoPanelPlot does this with the origin and a line segment from the origin to another point (namely, 2  +  2  i).

grid  =  {{{Blue},  {-2,  2,  11},  {-2,  2,  
              11}}};
pt  =  {CadmiumOrange,  PointSize[0.03],  
          ComplexPoint[0]};
ray  =  {CobaltGreen,  Thickness[0.015],  
          ComplexCurve[
            t ( 2  +  2  I),  {t,  0,  
              1}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 3}, \ {grid}, \ \ {ray, \ 
            pt}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grid}, \ {ray, \ pt}}];\)\)

Notice that the line segment from the origin highlighted above was specified as a parameterized curve and represented in Mathematica as a ComplexCurve graphics primitive.  Why was ComplexCurve used rather than the simpler ComplexLine, as in the following modification of the preceding TwoPanelPlot expression?  See the section Highlighting complex curves and their images, below.

grid  =  {{{Blue},  {-2,  2,  11},  {-2,  2,  
              11}}};
pt  =  {CadmiumOrange,  PointSize[0.03],  
          ComplexPoint[0]};
ray  =  {CobaltGreen,  Thickness[0.015],  
          ComplexLine[{0,  
              2  +  2  I}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 3}, \ {grid}, \ \ {ray, \ 
            pt}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grid}, \ {ray, \ pt}}];\)\)

That seems to give exactly the same plot as when ComplexCurve was used.

⚠ Caution: It can be dangerous to find the images of line segments (such as ray) by using ComplexLine.  It only works if the image is another line segment—and that happens to be the case with the squaring function for lines through the origin.  For more about this, see the section Highlighting complex curves and their images, below.

Polar form: real and imaginary parts U(x,  y) and V(x,  y) of f(
        r (e^(i θ)))

The function being used is:

f[z]

For a polar argument, the function value is:

f[r Exp[I θ]]

To separate this into a sum U  +  i V, evaluate ComplexExpand at that function value:

ComplexExpand[f[r Exp[I θ]]]

Then f is described in polar form (for the domain) by
	f(
          r (e^(i θ)))  =  
        U(r,  θ)   +  i V(r,  θ),
where the functions U and V are given as below by Mathematica:

U[r_,  θ_]  :=  
      ComplexExpand[Re[f[r Exp[I θ]]]]
V[r_,  θ_]  :=  
      ComplexExpand[Im[f[r Exp[I θ]]]]

{U[r,  θ],  V[r,  θ]}

Using polar coordinates to visualize f as a mapping \(TraditionalForm\`f\  : \ ℂ\  -> \ ℂ\), that is,  \(TraditionalForm\`f\  : \ ℝ\^2\  -> \ ℝ\^2\)

This section uses David Park's add-on package Cardano3`ComplexGraphics` for visualizing f in terms of polar coordinates in the domain, and cartesian coordinates in the codomain.  (For information on how to do it with the built-in add-on package Graphics`ComplexMap`, see Appendix 1.)

Before proceeding,  be sure you have already defined the function f in Mathematica and have loaded Park's packages.

A basic two-panel plot with a polar grid

grid  =  {{{Blue},  {0,  2,  7},  {0,  π/2,  
              7}}};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          PolarGrid, \ {0, \ 4}, \ {grid}}, 
{{#\^2 &}, \ 
          PolarGrid, \ {0, \ 4, \ False}, \ {grid}}];\)\)

Try to figure out just what the list {0, 4} in the description of the two panels is specifying.  Also try to figure out what the second and third arguments {0, 2, 7} and {0, π/2, 7} of grid are specifying.  For help, you can study the result of evaluating the following two input cells:

?TwoPanelPlot

?PolarGrid

Using multiply-colored grids

You may use different colors (or gray scale, or thickness, or dashing treatment, etc.) for the circular arcs and segments of rays in a polar grid.  The trick is to create two grids, the first with no rays and the second with no circles.  For example:

\(\(\(grids = {{{MediumBlue}, {0, \ 2, \ 7}, {0, \ π/2, 
              0}}, {{AbsoluteDashing[{5}], VenetianRed}, {0\ , 2, 
              0}, {0, \ π/2, 11}}};\)\(
\)
    \)\)
\(\(TwoPanelPlot[
{{# &}, \ 
          PolarGrid, \ {0, \ 4}, \ {grids}}, 
{{#\^2 &}, \ 
          PolarGrid, \ {0, \ 4}, \ {grids}}];\)\)

Highlighting points or line segments

It's easy to highlight particular points, line segments, and circular arcs, and to see their images in the two-panel polar grid plot:

grid  =  {{{Blue},  {0,  2,  7},  {0,  π/2,  
              7}}};

    
pt  =  {CadmiumOrange,  PointSize[0.03],  
          ComplexPoint[0]};
ray  =  {CobaltGreen,  Thickness[0.015],  
          ComplexCurve[
            t (2  +  2  I),  {t,  0,  
              1}]};
quartercircle  =  {AlizarinCrimson,  Thickness[0.015],  
          ComplexCurve[
            (5/3) Exp[I θ],  {θ,  
              0,  (π/2)}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          PolarGrid, \ {0, \ 4}, \ {grid}, \ {ray, \ pt, \ 
            quartercircle}}, 
{{#\^2 &}, \ 
          PolarGrid, \ {0, \ 4, \ False}, \ {grid}, \ {ray, \ pt, \ 
            quartercircle}}];\)\)

Notice that the line segment from the origin highlighted above was specified as a parameterized curve and represented in Mathematica as a ComplexCurve graphics primitive.  The same was true for the circular arc.  Why was ComplexCurve used rather than the simpler ComplexLine and ComplexCircle, as in the following modification of the preceding TwoPanelPlot expression?  See the section Highlighting complex curves and their images, below.

grid  =  {{{Blue},  {0,  2,  7},  {0,  π/2,  
              7}}};

    
pt  =  {CadmiumOrange,  PointSize[0.03],  
          ComplexPoint[0]};
ray  =  {CobaltGreen,  Thickness[0.015],  
          ComplexLine[{0,  
              2  +  2  I}]};
quartercircle  =  {AlizarinCrimson,  Thickness[0.015],  
          ComplexCircle[0,  
            (5/3),  {0,  (π/2)}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          PolarGrid, \ {0, \ 4}, \ {grid}, \ \ {ray, \ pt, \ 
            quartercircle}}, 
{{#\^2 &}, \ 
          PolarGrid, \ {0, \ 4, \ False}, \ {grid}, \ {ray, \ pt, \ 
            quartercircle}}];\)\)

That seems to give exactly the same plot as when ComplexCurve was used—at least with regards to the highlighted point and the highlighted line segment.  However, the image of the arc seems to be missing.

⚠ Caution: It can be dangerous to find the images of line segments (such as ray) that way, using ComplexLine.  It only works if the image is another line segment—and that happens to be the case with the squaring function for lines through the origin.  For more about this, see the section Highlighting complex curves and their images, below.

Highlighting complex curves and their images

The notebook IntroComplexGraphics.nb showed how to use the function ComplexCurve from David Park's Cardano3 application to draw objects in the complex plane.  That same function ComplexCurve was used in the examples above, where the question was raised about why the simpler ComplexLine or ComplexCircle was not used instead.

Below you will learn how to enhance such graphical representations by including additional curves and their images—and how to do it safely, by using the Cardano3 function ComplexCurve.

Enhancing CartesianGrid plots

For example, here's a Cartesian representation of the squaring function again.  Images of a horizontal line and a vertical line are highlighted.

grid  =  {{{DimGray},  {-2,  2,  11},  {-2,  2,  
              11}}};

    
horizontal  =  {AlizarinCrimson,  Thickness[0.015],  
          ComplexCurve[(1  -  
                    t) (-2 +  (4/5) I)  +  
              t ( 2  +  (4/5) I),  {t,  0,  
              1}]};
vertical  =  {CobaltGreen,  Thickness[0.015],  
          ComplexCurve[(1  -  s) ((6/5)  -  
                    2  I)  +  
              s ((6/5)  +  2  I),  {s,  0,  
              1}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 3}, \ {grid}, \ {horizontal, \ 
            vertical}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grid}, \ {horizontal, \ 
            vertical}}];\)\)

⚠  Caution!  The following does not work as expected:

grid  =  {{{DimGray},  {-2,  2,  11},  {-2,  2,  
              11}}};

    
horiz  =  {AlizarinCrimson,  Thickness[0.015],  
          ComplexLine[{-2 +  (4/5) I,   2  +  (4/5) I}]};
vert  =  {CobaltGreen,  Thickness[0.015],  
          ComplexLine[{(6/5)  -  2  I,  
              (6/5)  +  2  I}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          CartesianGrid, \ {0, \ 3}, \ {grid}, \ {horiz, \ 
            vert}}, 
{{#\^2 &}, \ 
          CartesianGrid, \ {0, \ 8}, \ {grid}, \ {horiz, \ 
            vert}}];\)\)

We emphasize: the images shown in the right-hand panel of the preceding plot are not correct!  To understand why not, look again at the last two exercises in the section Using ComplexCurve in notebook IntroComplexGraphics.nb, and read the "fine print" below.

Why does the preceding input cell not correctly display the images of the line segments?  The answer lies in the way that TwoPanelPlot calculates the images of the graphics primitive objects.  Here those objects are defined by means of the graphics primitive ComplexLine. What TwoPanelPlot does is merely to take the particular points determining the graphics objects (here, the endpoints of the lines); calculates the images of those particular points; and finally forms the same kind of primitive graphics objects—lines, again—using those image points.  And under the squaring function, the image of a horizontal or vertical line is not another line!

As you saw earlier, the result of a ComplexCurve expression involves a whole list of points along the curve.  Then TwoPanelPlot calculates the images of all those points and connects the image points to obtain a new curve.  (You may need to be careful, therefore, that Mathematica actually finds enough points on the curve so as to give a faithful image when it "connects the dots" of the image points.  In case it does not, you may need to include a PlotPoints option in your ComplexCurve expression, for example:  PlotPoints -> 100.)

Enhancing PolarGrid plots

Here's a polar representation of the squaring function that highlights the image of a particular quarter-circle:

grid  =  {{{DimGray},  {0,  2,  7},  {0,  π/2,  
              7}}};

    
ray  =  {CobaltGreen,  Thickness[0.015],  
          ComplexLine[{0,  (Sqrt[2])  +  (Sqrt[2]) 
                  I}]};
quartercircle  =  {AlizarinCrimson,  Thickness[0.015],  
          ComplexCurve[(5/3) Exp[I θ],  {θ,  
              0,  (π/2)}]};

    
\(\(TwoPanelPlot[
{{# &}, \ 
          PolarGrid, \ {0, \ 
            4}, \ {grid}, \ {ray, \ \ quartercircle}}, 
{{#\^2 &}, \ PolarGrid, \ {0, \ 4, \ 
            False}, \ {grid}, \ {ray, \ \ quartercircle}}];\)\)

Now the image of the quarter-circle is correctly reproduced.

Example 2: adding 2 + i

f[z_]  :=  z  +  (2  +  I)

grid  =  {{{Blue},  {-2,  2,  7},  {-2,  
              2,   7}}};
redline  =  {AbsoluteThickness[3], Red,  
          ComplexLine[{0,  2   +  2  I}]};
TwoPanelPlot[
{{# &},  
          CartesianGrid,  {0,  3},  {grid},  
          redline}, 
{{f[#] &},  
          CartesianGrid,  {0,  5,  False},  {grid},  
          redline}];

Notice the form of the pure function f[#]& used above in the second line of arguments to TwoPanelPlot.  You could use instead # + (2 + i)&.  However, there is no need to do so since f is already defined.

Exercise.  Note the use of ComplexLine rather than the "safe" ComplexCurve in this example.  Is that OK—is the image of the line segment L represented by redline really the line segment that joins the images of the endpoints of L?  Why or why not?

Example 3: multiplication by i

f[z_]  :=  I z

Look first at how f maps a rectangular grid in the first quadrant and the line segment from the origin to the far corner of that rectangle:

grid  =  {{{Blue},  {0,  2,  7},  {0,  
              2,   7}}};
redline  =  {AbsoluteThickness[3], Red,  
          ComplexLine[{0,  2   +  2  I}]};
TwoPanelPlot[
{{# &},  
          CartesianGrid,  {0,  3},  {grid},  
          redline}, 
{{f[#] &},  
          CartesianGrid,  {0,  3,  False},  {grid},  
          redline}];

Now look first at how f maps a polar grid in the first quadrant and the same line segment as before:

grid  =  {{{Blue},  {0,  2,  7},  {0,  π/2,  
              7}}};
redline = {AbsoluteThickness[3], Red, 
          ComplexLine[{0, 
              2 (((Sqrt[2])/2)  +  ((Sqrt[2])/2) I)}]};
TwoPanelPlot[
{{# &},  
          PolarGrid,  {0,  3},  {grid},  
          redline}, 
{{f[#] &},  
          PolarGrid,  {0,  3,  False},  {grid},  
          redline}];

Exercise.  Note the use of ComplexLine rather than the "safe" ComplexCurve in this example (for both the cartesian grid and the polar grid drawings).  Is that OK—is the image of the line segment L represented by redline really the line segment that joins the images of the endpoints of L?  Why or why not?

Appendix 1: Quick-and-dirty visualization of functions by using the Standard Add-on package Graphics`ComplexMap`

Whereas you must install Park's Cardano3 packages (if you are working at your own computer rather than at a lab computer where it has already been installed), the "Standard" Add-on package Graphics`ComplexMap` comes as part of Mathematica.  However, you must still load this package before using it:

Needs["Graphics`ComplexMap`"]

Before proceeding, be sure you have already defined the function f in Mathematica.  (But you do not need to have loaded Park's Cardano3 packages.)

Mapping in terms of Cartesian coordinates—using Graphics`ComplexMap`

Return here to the function of example 1:

f[z_]  :=  (z^2)

dom  =  
        CartesianMap[Identity,  {-2, 2},  {-2,   2},  
          PlotRange  ->  All];

range  =  
        CartesianMap[f,  {-2, 2},  {-2,  2},  
          PlotRange  ->  All];

Show[GraphicsArray[{dom,  range}]];

Mapping in terms of polar coordinates—using Graphics`ComplexMap`

Still use here to the function of example 1:

f[z_]  :=  (z^2)

Before proceeding, be sure you have already loaded  Graphics`ComplexMap`.  (But you do not need to have loaded Park's Cardano3 packages.)

PolarMap[Identity,  {0, 2},  {0,   π/2},  
        PlotRange  ->  All];

PolarMap[f,  {0, 2},  {0,  π/2},  
        PlotRange  ->  All];

Appendix 2: DisplayFunction and the Cardano3 function DontShow

If you don't intend to draw "quick-and-dirty " representations of complex functions by using the functions CartesianMap and PolarMap from the standard add-on package Graphics`ComplexMap`, then you may want to skip this appendix on a first reading.

The Cardano3 function DontShow

Later in this appendix, David Park's Cardano3 function DontShow will be used below in conjunction with the functions CartesianMap and PolarMap from the Graphics`ComplexMap` standard add-on package.  (Park's Cardano3`ComplexGraphics`  routines typically take care of applying DontShow where needed.)

The rest of this section explains why DontShow will be used.

If you evaluate an expression that contains a Plot or many other graphics expressions (Plot3D, Graphics`ComplexMap`CartesianMap, etc.) , you will see that graphics plot is displayed whether you want to see it then or not.  To suppress seeing it, you may include the option DisplayFunction -> Identity in the Plot object.  Then, in the entire expression or a later expression with Show you would include the option DisplayFunction -> $DisplayFunction to cause the graphics object to be displayed.

Look, for example at what happens when you try to combine both a Plot and a Graphics object for a point on that graph:

grf  =  Plot[(x^2),  {x,  -2,  2}];  
    pt  =  Graphics[{PointSize[0.025],  Red,  
          Point[{1,  1}]}];
Show[{grf,  pt}];

You see the graph twice, once when it was created and then again as part of the final display.  Here's how to suppress the first display:

grf  =  
      Plot[(x^2),  {x,  -2,  2},  
        DisplayFunction  ->  Identity];  
    pt  =  Graphics[{PointSize[0.025],  Red,  
          Point[{1,  1}]}];
Show[{grf,  pt},  
        DisplayFunction  ->  $DisplayFunction];

That's rather wordy!  David Park's DrawGraphics application, whose relevant packages are loaded automatically when his Cardano3 packages are loaded, comes to the rescue with the handy function DontShow (and a companion, DoShow):

?DontShow

DontShow @ Plot[(x^2),  {x,  -2,  2}];  
    pt  =  Graphics[{PointSize[0.025],  Red,  
          Point[{1,  1}]}];
Show[{grf,  pt}];

Actually, all use of the DisplayFunction function option above—or its DontShow surrogate—could have been avoided by using the Plot option Epilog (or in other, similar situations, Prolog) to add graphics primitives directly to the plot, like this:

Plot[(x^2),  {x,  -2,  2},  
        Epilog  ->  {PointSize[0.025],  Red,  
            Point[{1,  1}]}];

Here's an example where you would definitely need to use either DontShow (or, directly, the DisplayFunction option) to suppress preliminary displays of plots.

squareGraph  =  
        DontShow @ 
          Plot[(x^2),  {x,  -2,  2}];
cubeGraph  =  
        DontShow @ 
          Plot[(x^3),  {x,  -2,  2}];
Show[
        GraphicsArray[{squareGraph,  cubeGraph},  
          ImageSize  ->  6 * 72]];

Using DontShow with CartesianMap and PolarMap

Example 2 revisited

f[z_]  :=  z  +  (2  +  I)

dom  =  
        DontShow @ 
          CartesianMap[Identity,  {-2, 2},  {-2,   2},  
            PlotRange  ->  All];
range  =  
        DontShow @ 
          CartesianMap[f,  {-2, 2},  {-2,  2},  
            PlotRange  ->  All];
Show[GraphicsArray[{dom,  range}],  
        ImageSize  ->  6 * 72];

To see why DontShow was useful above:  copy the preceding input cell to below; delete the leading DontShow @ expressions from the definitions of dom and range; and then evaluate the resulting input cell.

Example 3 revisited

f[z_]  :=  I z

dom  =  
        DontShow @ 
          CartesianMap[Identity,  {0, 2},  {0,   2},  
            PlotRange  ->  All];
range  =  
        DontShow @ 
          CartesianMap[f,  {0, 2},  {0,  2},  
            PlotRange  ->  All];
Show[GraphicsArray[{dom,  range}],  
        ImageSize  ->  6 * 72];

dom  =  
        CartesianMap[Identity,  {0, 2},  {0,   2},  
          PlotRange  ->  All];
range  =  
        CartesianMap[f,  {0, 2},  {0,  2},  
          PlotRange  ->  All];
Show[GraphicsArray[{dom,  range}],  
        ImageSize  ->  6 * 72];