# Plotting Complex Quantity Functions

Trying to plot with complex quantities seems not to work properly in what I want to accomplish. I would like to know if there is a general rule/way of plotting when you have complex counterparts in your function. I tried looking up ContourPlot and DensityPlot but I only have one single variable as ContourPlot asks for two variables in order to plot. The expression I am trying to plot is as so:

eqn := (25 Pi f I)/(1 + 10 Pi f I)
Plot[eqn,{f,-5,5}]


If there something else that is missing here?

-
Plot displays $\mathbb{R}\to\mathbb{R}$ functions. How is it supposed to interpret I? –  rcollyer Mar 25 '12 at 1:25
Is your variable f supposed to be just real (as suggested by the domain in your Plot expression)? Or do you want it to take more general complex values, too? –  murray Mar 25 '12 at 16:45
@murray: Well the function f is complex valued. It reads as G(f) = (25 Pi f I) / (1 + 10 Pi f I). So, what I was trying to accomplish is plot the spectrum or "Fourier Transform (frequency response)", of the function $g(t)$. Where $f$ just represent the frequency variable from the time-domain. I hope that makes sense to clear up your question. –  night owl Mar 26 '12 at 0:07
@night owl: a typical communication between a mathematician and a non-matthematician? (I think of a complex-valued function of a real variable; you speak about respone of frequency.) But I understand! You do have a function from the real numbers to the complex numbers, so the way to represent it visually is unclear. For things like density plots and contour plots, one is dealing with a domain consisting of pairs of reals or, equivalently,complex numbers and range real numbers. Your situation is precisely the reverse. –  murray Mar 26 '12 at 3:55
@murray: Edit: I meant to say the function G is complex, but can be seen from above. –  night owl Mar 26 '12 at 4:45

The way you could use ContourPlot here, assuming your variable f is complex (f == x + I y) :

eqn[x_, y_] := (25 Pi ( x + I y) I)/(1 + 10 Pi ( x + I y) I)

{ContourPlot[Re@eqn[x, y], {x, -1, 1}, {y, -1, 1}, PlotPoints -> 50],
ContourPlot[Im@eqn[x, y], {x, -1, 1}, {y, -1, 1},
PlotRange -> {-0.5, 0.5}, PlotPoints -> 50]}


These are respectively real and imaginary parts of the function eqn.

Let's plot the absolute value of eqn :

Plot3D[ Abs[ eqn[x, y]], {x, -1, 1}, {y, -1, 1}, PlotPoints -> 40]


And we complement with the plot of real and imaginary parts of eqn in the real domain :

eqnR[x_] := (25 Pi x I)/(1 + 10 Pi x I)
Plot[{ Tooltip@Re@eqnR[x], Tooltip@Im@eqnR[x]}, {x, -0.25, 0.25},
PlotStyle -> Thick, PlotRange -> All]


-
Nice To know how it would work to do it as a contour and how it looks. But I really just needed it to output a regular curve. I mentioned contour because I had looked up how to plot complex variables. I might have to accept the other answer as to that it what I was more so looking to get. It is to see what the frequency spectrum is of a function. –  night owl Mar 25 '12 at 1:55
I added the real and imaginary parts of eqn in one plot. Tooltips help to distinguish parts of eqn while the mouse pointer is on a given curve. –  Artes Mar 25 '12 at 2:42
You may have won back the title! This is what I got doing it in matlab, and gnu plot, but could not figure it out here. This is what the frequency response should resemble, from my results in the other programs. :). Did you make this possible still using Plot by using the Re@eqnR[x] and Im@eqnR[x].? –  night owl Mar 25 '12 at 4:02
@nightowl I'am not sure what you are asking for. You can remove Tooltip as well if you want, here it is superfluous. –  Artes Mar 25 '12 at 14:31
I would advise only to study the issue on a case by case basis, otherwise there is no resonable answer. –  Artes Mar 26 '12 at 0:32

The following function gives the complete information for a function $f:\mathbb{C}\mapsto\mathbb{C}$, by giving the absolute value as $z$-coordinate, and the argument as colour:

ComplexFnPlot[f_, range_, options___] :=
Block[{rangerealvar, rangeimagvar,g},
g[r_,i_]:=(f/.range[[1]]:>r+I i);
Plot3D[Abs[g[rangerealvar,rangeimagvar]],
{rangerealvar, Re[range[[2]]], Re[range[[3]]]},
{rangeimagvar, Im[range[[2]]], Im[range[[3]]]}, options,
ColorFunction->(Hue[Mod[Arg[g[#1,#2]]/(2*Pi) + 1, 1]]&),
ColorFunctionScaling->False]]


For example, the call

ComplexFnPlot[Gamma[z],{z,-3.5-3.5I,3.5+5.5I},PlotRange->{0,4}]


gives

Positive real numbers are red, negative real numbers are cyan. One can e.g. see that the poles of the Gamma function are of order one because going round them you go through the colour cycle just once.

-
Yes, such a plot does encode "complete information". But discerning from such a plot just how the function behaves is problematic. –  murray Apr 15 '12 at 14:57
@murray: No more problematic than any other information gathered from graphs. Of course, reading from a graph can never replace a proper analysis. However it can give strong hints about what one is likely to find in that analysis. –  celtschk Apr 15 '12 at 15:02

Just use ParametricPlot and split up the real and imaginary parts as shown below:

eqn = (25 Pi f I)/(1 + 10 Pi f I)
ParametricPlot[{Re[eqn], Im[eqn]}, {f, -5, 5}, AspectRatio -> 1]


Note that you can use Set (=) rather than SetDelayed (:=) here.

-
Thanks. When should one use the SetDelayed versus Set preferably. Because I know that I usually use and see others use it when defining independent variables to your function such as Artes has done. This looks a bit different from what I got using a different program. I wonder whats that about? –  night owl Mar 25 '12 at 1:57
–  Verbeia Mar 25 '12 at 2:19
Thanks, for that link. That was helpful to distinguish the two. :). –  night owl Mar 25 '12 at 3:23

Here are two common ways to visualize complex functions. The first plots the image of a rectangle in the complex plane. The second plots real and imaginary contours on top of one another, illustrating the fact that they meet at right angles.

f[z_] := E^z;
pic1=ParametricPlot[{Re[f[x+I*y]],Im[f[x+I*y]]},
{x,0,1},{y,0,Pi/2}, ImageSize -> 300];
pic2 = Show[
ContourPlot[Re[f[x+I*y]],{x,0,3},{y,0,Pi/2},