I already tried to ask this question, but it was unclear what I meant, so I will try to ask it again and explain it more carrefully.

For example I will use a toy problem. Suppose we have equation:

eq=k*x^2 + 2*x + 1


I want to use ContourPlot, to plot the curves where eq=0 for some values of x andk. If x and k are both real, this is easy to do:

ContourPlot[eq == 0, {k, 0, 2}, {x, -3, 3}]


But I want to treat x as complex variable, and k as real variable. For any real k we have 2 complex roots of the equation eq==0. I am not interested in Im[x], I only interested in Re[x]. So want I want is something like this:

ContourPlot[eq == 0, {k, 0, 2}, {Re[x], -3, 3}]


So, for each k, it should solve the equation eq==0, and plot Re[x] against k, omitting Im[x]. I want 2D plot, I don't want 3D plot. (My original problem is linear stability analythis, where x is groth rate, k is wave number).

Say it another way: basically, we have here 3 parameters (complex x + real k). I want to plot Re[x] against k, ignoring Im[x], so it is like a projection of 3D curve to 2D surface.

Note: Plotting Complex Quantity Functions doesn't solve my problem.

Note:

Manipulate[ContourPlot[k (reX + imX I)^2 + 2 (reX + imX I) + 1 == 0, {k, 0, 2}, {reX, -3, 3}], {imX, -3, 3}]


Doesn't solve it as well: I don't want to manipulate Im[x], I want to omit it, whatever it is.

• march, I add another explanation: this is like a projection of 3D curve (with parameters Re[x], Im[x], k) to 2D space (with only 2 parameters: Re[x] and k) – Mikhail Genkin Sep 22 '15 at 17:32
• march, there is no freedom: for each k, you can solve the equation and find 2 complex roots. So I want to plot real part of this roots against k, omitting imaginary part of the roots. Where did you find freedom?? – Mikhail Genkin Sep 22 '15 at 17:33
• How complicated is your general equation? Is it algebraically separable into real and imaginary parts if you write x = Re[x] + I Im[x]? Or will have you have imaginary numbers inside special functions like, say, Erf? – march Sep 22 '15 at 17:46
• march, it is of the third order, but numbers are crazy sometimes. I know, that I can separate it and solve for both real and imaginary part, then plot what I want. But it is much more safe to do ContourPlot, rather then solving it exactly – Mikhail Genkin Sep 22 '15 at 18:04
• Understood. @george2079's ContourPlot method is very clever. I'm working on another method that requires the separability, but it's hard to get it to work, so I may not end up posting an answer. – march Sep 22 '15 at 18:13

Here is a crude way to generate the plot:

Graphics[Point[
Flatten[Table[ {k, #} & /@
Re[x /. Solve[ k x^2 + 2 x + 1 == 0  , x]], {k, -3, 3, .01}],
1]], AspectRatio -> 1]


clipping the plot range..and with Axes->True

Edit: a trick to coax ContourPlot to do the job:

f[k_, x_] := (Re[y] /.
Solve[ k (x + y)^2 + 2 (x + y) + 1 == 0  , y] )[[1]]
g[k_, x_] := (Re[y] /.
Solve[ k (x + y)^2 + 2 (x + y) + 1 == 0  , y] )[[2]]
ContourPlot[{ f[k, x] == 0, g[k, x] == 0}, {k, -3, 3}, {x, -10, 10}]


• Thanks a lot! Is that possible to everything in log-log scale? – Mikhail Genkin Sep 22 '15 at 18:02
• work with ListLogLogPlot (wont work for the toy example however because there are no results for k,x both positive ) – george2079 Sep 22 '15 at 18:08
• Thanks again. That solves my problem. – Mikhail Genkin Sep 22 '15 at 18:09
• No, it's not. This is a root x=(-2+sqrt(4-k))/(2k). Unless k is very small, negative k results in a small x. Nice trick, btw, to assume x=a+b, where a is real, b is complex, and then set Re[b]=0, which automatically results in arbitrary pure imaginary b. – Mikhail Genkin Sep 22 '15 at 19:09
• x is not precisely zero there. I think, you are confusing x-axis with k-axis (horizontal axis is k axis, vertical is x-axis). If you are talking about vertical line k=0,than yes, there is a problem, but it arises from the fact, that the equation I provided is singular when k=0: it becomes first order. If you will try to use formula x=(-2+-sqrt(4-k))/(2k) for k=0, you will get 0/0 – Mikhail Genkin Sep 22 '15 at 19:52

Another way using ParametricPlot:

{k, Re[x]} /.
Solve[k x^2 + 2 x + 1 == 0, x] //
ParametricPlot[#, {k, -5, 5}] &


• @MikhailGenkin You're welcome :) – Silvia Sep 23 '15 at 17:54