# Contourplot of complex Roots

Suppose I have this equation:

$$z^2 + 3z + (x^2 + y^2) = 0$$

I want the real and complex contour plot of $z(x,y)$. Analytically, the real/imaginary boundary is separated by condition $x^2 + y^2 \leq \frac{9}{4}$

The regular contour plot only plots the real parts when I use findRoot:

eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0
ContourPlot[
z /. FindRoot[eqn[x, y, z], {z, 1}], {x, 0, 2}, {y, 0, 2},
PlotLegends -> Automatic] The darkest purple represents the complex area.

How do I obtain contour plots of real roots of z, imaginary roots of z? Also, if possible combine them into a single graph.

Tried this different approach of letting $z = a + bi$, but doesn't work.

 z = a + b I;
eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0
ContourPlot[
z /. FindRoot[Im[eqn[x, y, z]], {b, 1}], {x, 0, 2}, {y, 0, 2},
PlotLegends -> Automatic]


Plots from difficult problem: First one is real, second one is imaginary root contour plot.  • ListContourPlot? – Apple Jul 24 '14 at 12:43

How about using NSolve like this. As you know z roots are 2-sets. but I have tried the one of things.

eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0

opts := Sequence[
PlotLegends -> Automatic,
Exclusions -> {x^2 + y^2 == 9/4},
ExclusionsStyle -> Red,
ColorFunction -> "SunsetColors"];

rec = ContourPlot[
Re[z] /. NSolve[eqn[x, y, z], z][], {x, 0, 2}, {y, 0, 2},
Evaluate@opts, Contours -> 10] imc = ContourPlot[
Im[z] /. NSolve[eqn[x, y, z], z][], {x, 0, 2}, {y, 0, 2},
Evaluate@opts, Contours -> 10] ContourPlot[
If[x^2 + y^2 < 9/4,
Re[z] /. NSolve[eqn[x, y, z], z][],
Im[z] /. NSolve[eqn[x, y, z], z][]], {x, 0, 2}, {y, 0, 2},
Evaluate@opts, Contours -> 20
] Plot3D[
If[x^2 + y^2 < 9/4,
Re[z] /. NSolve[eqn[x, y, z], z][],
Im[z] /. NSolve[eqn[x, y, z], z][]], {x, 0, 2}, {y, 0, 2},
Evaluate@opts, Mesh -> 20, MeshFunctions -> {#3 &}
] You can't Plot a complex function. But you can always plot the Re and Im part of the solution.

eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0
sol[x_,y_]=z/.Solve[eqn[x,y,z],z]
ContourPlot[Re[sol[x,y]][],{x,0,2},{y,0,2},MaxRecursion->3,PlotLabel->"Real"]
ContourPlot[Im[sol[x,y]][],{x,0,2},{y,0,2},MaxRecursion->3,PlotLabel->"Imaginary"] similarly you can also plot the other solution.

EDIT : With FindRoot

eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0
ContourPlot[z /. FindRoot[eqn[x, y, z], {z, 1. I}, MaxIterations -> 100] //Re, {x, 0, 2}, {y, 0, 2},PlotLabel -> "Real"]
ContourPlot[z /. FindRoot[eqn[x, y, z], {z, 1. I}, MaxIterations -> 100] //Im, {x, 0, 2}, {y, 0, 2},PlotLabel -> "Imaginary"] • Does this work with FindRoot as well? Because I'm applying it to a more difficult problem that uses FindRoot – user44840 Jul 24 '14 at 12:40
• try a complex initial value like 0.+ I in FindRoot. – Sumit Jul 24 '14 at 12:43
• Let's say that I can only use FindRoot for my difficult problem. I applied it to this (simpler)problem, and it doesn't seem to work. eqn[x_, y_, z_] := z^2 + 3 z + x^2 + y^2 == 0 ContourPlot[ z /. FindRoot[eqn[x, y, z], {z, 1.4 I}], {x, 0, 2}, {y, 0, 2}, PlotLegends -> Automatic] – user44840 Jul 24 '14 at 12:52
• @user44840 : you didn't mention Re or Im, that's you get the plot for only real region and white space for imaginary portion. Have a look at my modified answer. – Sumit Jul 24 '14 at 13:04
• Hmm that works! But in the imaginary plot, why are there such rough and random contours? How do you separate which is real and imaginary then? (i.e. identify the boundary). I've uploaded pictures of the real and imaginary contour plots. From the real plot, it seems like there's an imaginary root in some regions, while the imaginary contour plot is a mess. – user44840 Jul 24 '14 at 13:11