Function Repository Resource:

ComplexMapVisualization

Source Notebook

Visualize the behavior of conformal mappings in the complex plane

Contributed by: Duncan Pettengill

ResourceFunction["ComplexMapVisualization"][f]

returns the ImageTransformation of a given function f on the complex plane.

Details and Options

f can be any function that accepts a complex number as input and returns a complex number as output.
ResourceFunction["ComplexMapVisualization"] inherits options from ImageTransformation and Rasterize, which are passed to those functions during evaluation.
ResourceFunction["ComplexMapVisualization"] also has an "Image" option, so that mappings can be visualized on different base images. The default image is a grid of red and green lines.
With default option settings, the image is mapped using a DataRange and PlotRange of {{0,1},{0,1}}.

Examples

Basic Examples (3) 

Visualize the sine function in the complex plane:

In[1]:=
ResourceFunction["ComplexMapVisualization"][Sin[2 #] &]
Out[1]=

Mappings on different sections of the complex plane can be visualized by specifying a different DataRange or PlotRange:

In[2]:=
ResourceFunction["ComplexMapVisualization"][Sin, PlotRange -> {{-Pi, Pi}, {0, Pi}}, RasterSize -> 200]
Out[2]=

Forward transformations can be created by using the inverse function:

In[3]:=
ResourceFunction["ComplexMapVisualization"][ArcSin, PlotRange -> {{-Pi, Pi}, {0, Pi}}, RasterSize -> 200]
Out[3]=

Scope (3) 

Standard special functions can be visualized:

In[4]:=
ResourceFunction["ComplexMapVisualization"][Gamma, PlotRange -> {{-3, 3}, {-1, 1}}]
Out[4]=

General functions that have complex values as their domain and range can be visualized:

In[5]:=
ResourceFunction["ComplexMapVisualization"][
 Function[z, (z - 1)/(z^2 + 2)], PlotRange -> {{-3, 3}, {-3, 3}}, RasterSize -> 150]
Out[5]=

Compiled functions can be visualized:

In[6]:=
cf = Compile[{{x, _Complex}}, Sin[x] + x^2 - 1/(1 + x)]
Out[6]=
In[7]:=
ResourceFunction["ComplexMapVisualization"][cf, PlotRange -> {{-1.5, 1.5}, {-1, 1}}]
Out[7]=

Options (2) 

The "Image" option can be set to visualize mappings on arbitrary images or graphics objects:

In[8]:=
ResourceFunction["ComplexMapVisualization"][Cosh, PlotRange -> {{-2, 2}, {-2, 2}}, "Image" -> ExampleData[{"TestImage", "Mandrill"}], RasterSize -> 100]
Out[8]=

Use the "Image" option to see the transformation of a polar grid:

In[9]:=
ResourceFunction["ComplexMapVisualization"][ProductLog, PlotRange -> {{-1, 1}, {-1, 1}}, "Image" -> \!\(\*
GraphicsBox[
{RGBColor[0, 1, 0], Thickness[0.01], CircleBox[{0, 0}, 0.], CircleBox[{0, 0}, 0.1], CircleBox[{0, 0}, 0.2], CircleBox[{0, 0}, 0.30000000000000004], CircleBox[{0, 0}, 0.4], CircleBox[{0, 0}, 0.5], CircleBox[{0, 0}, 0.6000000000000001], CircleBox[{0, 0}, 0.7000000000000001], CircleBox[{0, 0}, 0.8], CircleBox[{0, 0}, 0.9], CircleBox[{0, 0}, 1.], CircleBox[{0, 0}, 1.1], CircleBox[{0, 0}, 1.2000000000000002], CircleBox[{0, 0}, 1.3], CircleBox[{0, 0}, 1.4000000000000001], 
{RGBColor[1, 0, 0], 
TagBox[ConicHullRegionBox[{0, 0}, {{1, 0}}],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{(Rational[
              5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[1, 2],
             Rational[1, 4] (-1 + 5^Rational[1, 2])}}, {{
          0.9510565162951535, 0.30901699437494745`}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{Rational[1, 4] (1 + 5^Rational[1, 2]), (
             Rational[
              5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
             1, 2]}}, {{0.8090169943749475, 0.5877852522924731}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{(Rational[
              5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
             1, 2], Rational[1, 4] (1 + 5^Rational[1, 2])}}, {{
          0.5877852522924731, 0.8090169943749475}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{Rational[1, 4] (-1 + 5^Rational[1, 2]), (
             Rational[
              5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
             1, 2]}}, {{0.30901699437494745`, 0.9510565162951535}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, {{0, 1}}],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{Rational[1, 4] (1 - 5^Rational[1, 2]), (
             Rational[
              5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
             1, 2]}}, {{-0.30901699437494745`, 0.9510565162951535}}]],
        
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{-(Rational[
               5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
              1, 2], Rational[1, 4] (
             1 + 5^Rational[1, 2])}}, {{-0.5877852522924731, 0.8090169943749475}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{Rational[1, 4] (-1 - 5^Rational[1, 2]), (
             Rational[
              5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
             1, 2]}}, {{-0.8090169943749475, 0.5877852522924731}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, NCache[{{-(Rational[
               5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
              1, 2], Rational[
             1, 4] (-1 + 5^Rational[1, 2])}}, {{-0.9510565162951535, 0.30901699437494745`}}]],
"InfiniteLine"], 
TagBox[ConicHullRegionBox[{0, 0}, {{-1, 0}}],
"InfiniteLine"]}},
PlotRange->1]\)]
Out[9]=

Options available to Rasterize affect the quality of the resulting image:

In[10]:=
ResourceFunction["ComplexMapVisualization"][Cosh, PlotRange -> {{-2, 2}, {-2, 2}}, "Image" -> ExampleData[{"TestImage", "Mandrill"}], RasterSize -> 20]
Out[10]=

Properties and Relations (1) 

Using ParametricPlot on the inverse function gives a result similar to the one produced by ComplexMapVisualization:

In[11]:=
With[{f = ArcSin}, {ResourceFunction["ComplexMapVisualization"][f, PlotRange -> {{-1, 1}, {-1, 1}}], ParametricPlot[
    ReIm[InverseFunction[f][x + I y]], {x, -1, 1}, {y, -1, 1}, {BoundaryStyle -> None, ImageSize -> Large, Mesh -> Automatic, MeshStyle -> {
RGBColor[0, 1, 0], 
RGBColor[1, 0, 0]}, PlotStyle -> GrayLevel[1]}]} // GraphicsRow]
Out[11]=

Possible Issues (2) 

With a sufficiently large PlotRange, the computation may take a long time:

In[12]:=
AbsoluteTiming[
 ResourceFunction["ComplexMapVisualization"][Exp, PlotRange -> {{-2, 2}, {-2, 2}}]]
Out[12]=

You can use the RasterSize option to reduce the quality of the input image and reduce the computation time:

In[13]:=
AbsoluteTiming[
 ResourceFunction["ComplexMapVisualization"][Exp, PlotRange -> {{-2, 2}, {-2, 2}}, RasterSize -> 150]]
Out[13]=

Publisher

Duncan Pettengill

Version History

  • 1.0.0 – 27 June 2022

Related Resources

Author Notes

Credit to Oleg Marichev for highlighting the need for a good complex visualization function.

License Information