Free Software to Plot Complex Functions as Maps of Grids – Complex Analysis

complex-analysisgraphing-functions

I teach an introductory course in Complex Analysis and it would help me a lot if I could use a free online tool to plot how a particular function maps a given grid in $z$-plane to $w$-plane but I am unable to find anything close to what I want. To specify a bit more:

  • Needham's book Visual Complex Analysis uses exactly this approach;
  • I am NOT interested in anything using coloring plotting;
  • I tried Sage but could not find what I wanted (it would be great if Sage did because it is a free pretty much universal math software).

Do you possibly know about such a tool? I know one could write a code for that but that is not what I am asking about – ideally, one would define a function (an elementary one) and then specify a grid (say an $x$-range and $y$-range and number of horizontal and vertical lines) and it would draw the picture of the grid transformed by the function.

Best Answer

Most programs that support Matlab-style or NumPy-style array operations and plotting can do that. Examples are Octave, FreeMat, or Scilab. The essence (in Octave syntax), demonstrated for the $\tanh$ function, is:

n=30;
[X,Y]=ndgrid([-pi/2:pi/n:pi/2],[-pi/2:pi/n:pi/2]);
Z=X+1i*Y;
W=tanh(Z);
clf(); axis([-4,4,-3,3],"equal"); hold on;
plot(W);
plot(W');

But then the segments between the grid points will be straight. You may want a little more refinement. Run the following as a script file or enter its contents in the Octave UI:

#! /usr/bin/env octave -qf
# Set plot ranges and aspect ratio
clf(); axis([-4,4,-3,3],"equal"); hold on;
# Set plot title
title("Map of tanh(z) resp. isolines of artanh(z)");
# Set number of subintervals of the domain used (in each direction)
n=360;
# Plot only each m-th curve. This makes hi-res arcs appear curved.
m=12;
# The square domain, subdivided
[X,Y]=ndgrid([-pi/2:pi/n:pi/2],[-pi/2:pi/n:pi/2]); Z=X+1i*Y;
# The image
W=tanh(Z);
# Plot image of every m-th line for which real(Z)=const.
# Hint: Specify ";;" to suppress the legend for octave < 2.9.13
plot(real(W(1:m:n+1,:))',imag(W(1:m:n+1,:))',";;");
# Plot image of every m-th line for which imag(Z)=const.
plot(real(W(:,1:m:n+1)),imag(W(:,1:m:n+1)),";;");
print("-dpng", "-mono", "-solid", "-S480,360", "tanh-map.png");

tanh-map

Related Question