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)

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
up vote 28 down vote accepted

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]}

enter image description here

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]

enter image description here

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]

enter image description here

  • 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
  • 1
    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



resulting graphics from the command above

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
  • 1
    @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

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;
  {x,0,1},{y,0,Pi/2}, ImageSize -> 300];
pic2 = Show[
    ContourShading -> False],
    ContourShading -> False],
    AspectRatio -> Automatic, ImageSize -> 400

There should be many more examples at the Wolfram Demonstrations site.

enter image description here

  • Such a domain-codomain representation can be made more meaningful by using various dynamic treatments, e.g., allowing the user to move a Locator in the domain and seeing its image in the codomain; or moving (for such a polar plot) the radial segment or the circular arc and seeing the corresponding image in the codomain. And David Park's Presentations application makes doing this easier, since among other things it can directly process geometric objects described in terms of complex numbers without having to separate things into real and complex parts. – murray Apr 15 '12 at 15:03
  • @murray Like this one:…? – Mark McClure Apr 15 '12 at 19:15
  • no, not quite like your demonstration (except that, like all such, it makes certain curves to curves). The ones by David Park and I (1) use polar as well as rectangular coordinates; either map a Locator point to its image or else vary a parameter to move a curve in domain and its image in codomain; use Presentations for simplicity in programming and true-to-the-spirit direct use of complex numbers and complex-valued curves. – murray Apr 16 '12 at 0:17

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]

enter image description here

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
  • 1
    Try this:… – 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

protected by xzczd May 16 '17 at 12:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.