0
$\begingroup$

I want to plot some contour cuvres of a simple function $f(z)=((z + 1/z)^2 - 4)*(1 - I)$.

The code ComplexContourPlot[Im[((z + 1/z)^2 - 4)*(1 - I)] == 0, {z, 2}] generates a nice curve $\Im[f(z)]=0$, see the figure attached.

Now I want to plot the part of the curve $\Im[f(z)]=0$ with $\Re[f(z)]>0$. I couldn't figure out how to realize this condition when plotting. Thanks in advance.

Plot of Im=0.

$\endgroup$

1 Answer 1

4
$\begingroup$

Use RegionFunction

Clear["Global`*"]

f[z_] := ((z + 1/z)^2 - 4)*(1 - I)

Legended[
 Show[
  ComplexContourPlot[Im[f[z]] == 0, {z, 2},
   ContourStyle -> Red,
   RegionFunction -> Function[{z, func}, 0 < Re[f[z]]],
   PlotPoints -> 75],
  ComplexContourPlot[Im[f[z]] == 0, {z, 2},
   ContourStyle -> Blue,
   RegionFunction -> Function[{z, func}, Re[f[z]] <= 0],
   PlotPoints -> 75]],
 Placed[LineLegend[{Red, Blue},
   {"Re(f(z))>0", "Re(f(z))≤0"}], {.7, .8}]]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thank you very much. This is beautiful. In your RegionFunction, you used two variables {z, func}. It appears that one variable {z} also does the job. Could you explain why you picked those two variables instead of one? $\endgroup$
    – Pengfei
    Commented Apr 10, 2021 at 13:32
  • $\begingroup$ There are two variables available. Since you only want to use the first, you can specify either one or two. It is just personal preference in that situation. $\endgroup$
    – Bob Hanlon
    Commented Apr 10, 2021 at 13:39
  • $\begingroup$ I see. Thank you for the explanation. $\endgroup$
    – Pengfei
    Commented Apr 10, 2021 at 13:57
  • $\begingroup$ If brevity is important you could also use Legended[Show[ComplexContourPlot[Im[f[z]] == 0, {z, 2}, ContourStyle -> #[[2]], RegionFunction -> #[[1]], PlotPoints -> 75] & /@{{0 < Re[f[#]] &, Red}, {Re[f[#]] <= 0 &, Blue}}], Placed[LineLegend[{Red, Blue}, {"Re(f(z))>0", "Re(f(z))\[LessEqual]0"}], {.7, .8}]] $\endgroup$
    – Bob Hanlon
    Commented Apr 10, 2021 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.