# Is there a simple way to plot complex numbers satisfying a given criteria

I think this should be straightforward, but I cannot seem to find a good source on how to do it after searching around, so

I'm trying to sketch sets of complex numbers that meet a given for criteria. For inequalities, I can get a sketch using RegionPlot. For instance, I can obtain the inequality $|z| < 1$ by

RegionPlot[Abs[z]<1,{x,-1.5,1.5},{y,-1.5,1.5}]


However, given the equality $z + \bar{z} = |z|^2$ I cannot seem to figure out how to get Mathematica to sketch the set of point in the complex plane meeting that criteria. Is there a simple way to accomplish this? (I'm self-studying a complex analysis book that has a bunch of these exercises, and I'd like to just quickly visualize what's going on in all the examples.) Thanks in advance for your help.

-

Use ContourPlot for equalities:

ContourPlot[
Evaluate[z + Conjugate[z] == Abs[z]^2 /. z -> x + I y],
{x, -2, 2},
{y, -2, 2},
FrameLabel -> Automatic
]


-
Great, thank you, exactly what I was looking for. Obviously, I should have found this searching, but for some reason it didn't turn up. – user600 Apr 24 '12 at 3:52

As David said, you can use ContourPlot. But if you'd prefer to keep using RegionPlot as you appear to have been doing, that could be fine too. All you have to do is to formulate your condition as an inequality. So I'll just copy David's code and do that:

RegionPlot[
Evaluate@ComplexExpand[
z + Conjugate[z] < Abs[z]^2 /. z -> x + I y], {x, -2, 2}, {y, -2,
2}, AxesLabel -> Automatic]


Here, I also had to replace Evaluate by Evaluate@ComplexExpand to make sure there are no spurious imaginary parts (0.I) - ComplexExpand causes variables to be considered real numbers.

The boundary appearing in the RegionPlot is now of course the thing you're looking for, because it represents the equality.

-
Thanks, that's roughly what I had been doing, to get an idea, but figured there had to be a straightforward way to get it done rather than a work around. – user600 Apr 24 '12 at 3:54
OK - then I guess my main message here could be: ComplexExpand is useful when plotting stuff because it helps avoid spurious imaginary parts that often cause inexplicably blank plots... – Jens Apr 24 '12 at 4:02

Let's define an appropriate function :

f[x_, y_] :=  FullSimplify[-(Abs[x + I y])^2 + (x + I y + Conjugate[x + I y]),
Element[x | y, Reals]]
f[x, y] // Expand

2 x - x^2 - y^2


To realize what sort of set is f[x,y] == 0 we solve this equation :

sols = Last @@@ (Solve[f[x, y] == 0, {x, y}, Reals] // Quiet)

{ ConditionalExpression[-Sqrt[2 x - x^2], 0 <= x <= 2],
ConditionalExpression[Sqrt[2 x - x^2], 0 <= x <= 2]  }

Plot[sols, {x, -2, 2}, AspectRatio -> Automatic]


We can use also ContourPlot, sometimes it satisfies one's needs even more than Plot or RegionPlot and in a straightforward way we make use of an option Axes -> True and add a circle where the contour line has the value 0 (i.e. f[x,y] == 0) :

ContourPlot[ f[x,y], {x, -2, 2}, {y, -2, 2},
Epilog -> {Darker@Green, Circle[{1, 0}, 1], PointSize[0.01], Point[{1, 0}]},
Axes -> True, Frame -> False]


Here the edge of the white circle (2 x - x^2 - y^2 == 0) was marked in a green color, and the other contour lines denote values a == f[x,y] == 2 x - x^2 - y^2, respecitively for a in the following set : { -2,-4,-6,-8,-10}.

We could specify as well to draw the only contour line f[x,y] == 0 this way :

ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, Contours -> {0}, Axes -> True]

-
Very nice. Obviously, I'm going to have to go read up on ContourPlot now :) – user600 Apr 24 '12 at 3:57