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)

If there something else that is missing here?

night owl

Posted 2012-03-25T01:12:45.057

Reputation: 1 669

Plot displays $\mathbb{R}\to\mathbb{R}$ functions. How is it supposed to interpret I? – rcollyer – 2012-03-25T01:25:31.217

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 – 2012-03-25T16:45:36.060

@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 – 2012-03-26T00:07:58.883

@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 – 2012-03-26T03:55:27.730

@murray: Edit: I meant to say the function G is complex, but can be seen from above. – night owl – 2012-03-26T04:45:55.013

@night owl: Stating "the function G is complex" is ambiguous. What is its domain? (just reals or all complex numbers?) Clearly its codomain is the complex numbers. – murray – 2012-03-26T14:04:05.143



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


Posted 2012-03-25T01:12:45.057

Reputation: 51 831

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 – 2012-03-25T01:55:51.693

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 – 2012-03-25T02:42:32.773

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 – 2012-03-25T04:02:06.107

@nightowl I'am not sure what you are asking for. You can remove Tooltip as well if you want, here it is superfluous. – Artes – 2012-03-25T14:31:27.467

I understand what you were doing with Tooltip. I was asking was using {Re[], Im[]} inside the Plot command gave the ability to view the real and imaginary components of the equation or if desired just one or the other. Because, when these are not used but instead Plot[eqn,{f,xmin,xmax}], nothing is rendered in the output. And as a user, you wonder to yourself, what is this telling me because there was no errors, but nothing was plotted. So, I was just asking were Re[] and Im[] the key to get the results to display when plotting a complex quantity using the Plot command. – night owl – 2012-03-25T23:35:02.903

@nightowl I could agree there should be a message why it did not produce a reasonable plot, however you can expect there are two real components of the function eqn and M cannot decide what to do. This construct {Re[], Im[]} is a general approach to produce a few curves, you can add even more components therein, e.g. {Re[], Im[], Abs@eqn[]}. – Artes – 2012-03-25T23:43:16.770

Yes, your are right. That would be a great feature if Mathematica can realize what you are trying to feed it to do and give slight suggestions as how you could adjust your input to get what you are looking for. Maybe in a furture version :). But yes, that also works nicely, the Abs[eqn]. Though, Abs@eqn[] does not display the Abs of the function with the empty argument brackets [] placed there, but when removed works perfectly as: Abs@eqn – night owl – 2012-03-26T00:00:50.670

Another question that comes to mind looking at one of the plots in comparison to the others. What information does the ContourPlot convey about your function? I guess what I am asking is, could it be some different domain where your function lies where it conveys certain vital information about the function you have, that could be helpful to you, depending on what type of analysis one is doing. If this makes sense? – night owl – 2012-03-26T00:11:02.127

1I would advise only to study the issue on a case by case basis, otherwise there is no resonable answer. – Artes – 2012-03-26T00:32:40.220

Okay, Thank You. – night owl – 2012-03-26T00:33:45.217


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.


Posted 2012-03-25T01:12:45.057

Reputation: 18 543

Yes, such a plot does encode "complete information". But discerning from such a plot just how the function behaves is problematic. – murray – 2012-04-15T14:57:17.193

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 – 2012-04-15T15:02:37.453


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

Mark McClure

Posted 2012-03-25T01:12:45.057

Reputation: 31 084

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 – 2012-04-15T15:03:01.460

@murray Like this one:

– Mark McClure – 2012-04-15T19:15:11.047

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 – 2012-04-16T00:17:15.067


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.


Posted 2012-03-25T01:12:45.057

Reputation: 33 191

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 – 2012-03-25T01:57:59.740

Thanks, for that link. That was helpful to distinguish the two. :). – night owl – 2012-03-25T03:23:15.143


There are several new functions in M12 that can be used to plot complex values. For functions of a real variable there are ReImPlot and AbsArgPlot. For your function they give:

ReImPlot[eqn, {f, -.25, .25}]

enter image description here

AbsArgPlot[eqn, {f, -.25, .25}, PlotRange->{{-.25,.25},{0, 2.5}}]

enter image description here

For visualizations over a complex domain, you can use ComplexPlot or ComplexPlot3D. Using celtschk's example of Gamma[z]:

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

enter image description here

Carl Woll

Posted 2012-03-25T01:12:45.057

Reputation: 112 778