# Contour plot of complex function: problem in choosing argument

I have a complex function F[x,y], and now I want to plot the contour F[x,y] = 0. What can I do in order to have the contour plot vs Re[x] and y (That is, I want to treat y a real variable and x a complex one)?

Thanks you very much!

• In my problem, I want to have a freedom to choose to plot the contour vs Re[x] and y OR x and Re[y]. And I don't know how to control it. – KenLee Aug 2 '13 at 9:18

Let me make sure I understand your question correctly, taking your comments into account. You have a function $f:\mathbb C\times\mathbb C\to\mathbb C$. You want to plot the set of points $(a,b)\in\mathbb R^2$ such that $f(a+ic,b+0i)=0$ for some $c\in\mathbb R$. Right? Let me know if I've misinterpreted your question.

Aside: The entire zero set of $f$, the set of all points $(x,y)\in\mathbb C^2$ such that $f(x,y)=0$, can be interpreted geometrically as a two-dimensional real surface embedded in four-dimensional real space $\mathbb C^2\cong\mathbb R^4$. Your desired plot amounts to slicing the surface along $\operatorname{Im}y=0$, and projecting it under $x\mapsto\operatorname{Re}x$, to get a one-dimensional curve in $\mathbb R^2$ (corresponding to $(\operatorname{Re}x,\operatorname{Re}y)$).

Here's one way to do this. We have three real degrees of freedom, $a$, $b$, and $c$, with $x=a+ic$ and $y=b+0i$. The contour $f(x,y)=0$ is a curve in three-dimensional $(a,b,c)$ space, defined implicitly by two real equations $\operatorname{Re}f(x,y)=0$ and $\operatorname{Im}f(x,y)=0$. Fortunately there are very elegant ways to plot such a curve.

f[x_, y_] := x^2 + y^2 - 1

With[{x = a + I c, y = b + 0 I},
ContourPlot3D[{Re@f[x, y], Im@f[x, y]},
{a, -2, 2}, {b, -2, 2}, {c, -2, 2}, Contours -> {0}, Mesh -> None,
ContourStyle -> {Directive[Lighter@Lighter@Blue, Opacity[0.4]],
Directive[Lighter@Lighter@Red, Opacity[0.4]]},
BoundaryStyle -> {1 -> None, 2 -> None, {1, 2} -> ColorData[1, 1]},
PlotPoints -> 50, MaxRecursion -> 0]] Aside: I used Maxim Rytin's method in Daniel Lichtblau's answer because Szabolcs's method draws extraneous curves at the plot boundaries. Also, for some reason the contours seem to get broken up if MaxRecursion is nonzero.

Now we can rid of the $c$ coordinate in the plot just by looking at it from an orthogonal top-down view. But there is another problem: we have to set a finite range for $c$ in the plot, but there might be points on the curve which require arbitrarily large values of $c$. No problem! We'll let $c=g(t)$ for some function $g$ which maps a finite range to all of $\mathbb R$, and plot against $t$ instead. I like to use the logit function for this purpose, but you could use $\tan$, $\tanh^{-1}$, or anything like that.

With[{x = a + I (Log[t] - Log[1 - t]), y = b + 0 I},
ContourPlot3D[{Re@f[x, y], Im@f[x, y]},
{a, -2, 2}, {b, -2, 2}, {t, 0, 1}, Contours -> {0}, Mesh -> None, ContourStyle -> None,
BoundaryStyle -> {1 -> None, 2 -> None, {1, 2} -> ColorData[1, 1]},
ViewPoint -> {0, 0, Infinity}, PlotPoints -> 50, MaxRecursion -> 0]] • Thanks you for your detailed reply. I think you've got my question and the answer is useful. But when I copy you code to the mathematica and try to generate the result, the outcome is very strange... maybe my function is too complicate for the mathematica to solve and plot. – KenLee Aug 7 '13 at 14:59
• Yes, this sort of plot can get pretty complicated pretty quickly. You could try doing the 3D plot first to see if Mathematica's getting the intermediate result right. – user484 Aug 7 '13 at 15:25
• Can I ask you different question that I encountered in doing the calculation? For the same function F[x,y], originally I want to find the value of x (complex) for a value of y, using the "FindRoot", but it turns out that it gave me different answers for slightly different starting points... Can I improve this? – KenLee Aug 7 '13 at 16:49
• Maybe $f(x,y)$ has multiple roots. What do you expect? It's hard to say more without knowing the form of $f$. – user484 Aug 8 '13 at 1:47
• The form is too complicated to show here. The problem is that the result of "FindRoot" is very sensitive to the starting value, so that it is difficult for me to use "FindRoot" to Listplot a smooth curve (Points just jumped everywhere.....), Is there any way besides Findroot that I can use in achieving the aim?? – KenLee Aug 8 '13 at 15:53

F[x_, y_] := Sin[Sin[x - y]] + I Cos[Cos[x + y]];

With[{x = a - 3 I},
ContourPlot[{Re[F[x, y]] == 0, Im[F[x, y]] == 0}, {a, -1, 1},
{y, -3/2, 3/2}, FrameLabel -> (Text[Style[#, Italic, 16]] & /@ {"Re x", "y"})]
]


which produces • Thanks you for your answer. In your answer it seems that you have assumed the Im[x] to be a constant, but when you solve F[x,y] = 0 for different values of y, you will have different Im[x]. It is ok to assume that Im[x] to be a constant to plot the contour? I forget to mention one thing: The coefficients in F[x,y] are generally complex. – KenLee Aug 2 '13 at 11:10
• @KenLee I do not know if Im[x], I've assumed this to sketch this example. – mmal Aug 2 '13 at 12:15
• If I don't want to assume Im[x] to be a constant, but a value satisfying F[x,y] = 0 at particular y (y should be a variable under plotting), can I do that? – KenLee Aug 2 '13 at 14:39