2
$\begingroup$

How do I plot the imaginary part of the function while its real part is positive?

For example, for the below code I could have the imaginary part but I am not able to find the positive or negative real part of the function.

ContourPlot[{Im[x + I*y - Log[x + I*y]]}, {x, -6, 8}, {y, -6, 6}, Contours -> {0}]
$\endgroup$
5
  • 2
    $\begingroup$ ContourPlot[Im[x + I y - Log[x + I y]], {x, -6, 8}, {y, -6, 6}, RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0]] $\endgroup$ – user484 Jan 13 '16 at 21:58
  • $\begingroup$ Hi Raul, for this command, are we first picking up the values of x and y, that satisfies the Re()>0, and then it plots the imaginary part? If so, If I want to add one more function in to this plot, How could I do it? Thank you $\endgroup$ – Jane Jan 14 '16 at 10:15
  • $\begingroup$ @Rahul, in this case, say I also want to plot this function x + I y - 4*Log[x + I *y] - 4 + 4*Log[4], how could I plot both in the same plot? Thank you $\endgroup$ – Jane Jan 14 '16 at 10:35
  • $\begingroup$ In that case you have to think about what you want drawn in the region where the real part of both functions is positive. $\endgroup$ – user484 Jan 14 '16 at 19:25
  • $\begingroup$ There are things to do after your question is answered. It's a good idea to stay vigilant for some time, better approaches may come later improving over previous replies. Experienced users may point alternatives, caveats or limitations. New users should test answers before voting and wait 24 hours before accepting the best one. Participation is essential for the site, please come back to do your part tomorrow $\endgroup$ – rhermans Jan 20 '16 at 16:21
4
$\begingroup$

I'm posting this to put Rahul's answer, given in a comment to the question, on record.

ContourPlot[Im[x + I y - Log[x + I y]], {x, -6, 8}, {y, -6, 6},
  Contours -> {0}, 
  RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0]]

plot

The yellow regions are positive and the blue regions are negative.

The plot can be much cleaner if a nicer ColorFunction is used and the cutoff at Re[function]==0 is not so abrupt:

ContourPlot[Im[x + I y - Log[x + I y]], {x, -2, 6}, {y, -6, 6}, 
 Contours -> 16, (* 16 contours seemed like a good number *)
 BoundaryStyle -> {Thick, Gray}, (* this adds a nice line at the edge of the region *)
 RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0], 
 ColorFunction -> "TemperatureMap" (* cool colors are negative, warm - positive *)
]

plot2

There's still an artifact at y==0 && x<0. This is to be expected, Log[z] has a branch-cut on the negative real half-line.

$\endgroup$
0
1
$\begingroup$
ContourPlot[
 If[Re[x + I*y - Log[x + I*y]] > 0, Im[x + I*y - Log[x + I*y]], 0],
 {x, -6, 8}, {y, -6, 6}, 
PlotPoints -> 100, 
Contours -> {0}]
$\endgroup$
1
  • $\begingroup$ Hi @David, this command works but, there occurs a zigzag line, which I believe is the contour (Re()) picture of the function. Say, our function is x + I y - 4*Log[x + I *y] - 4 + 4*Log[4] , in this case, that zigzag line turns out to be a half infinity sign , which I don't want it to be in the plot. Would you please let me know if I could do something with it? Thank you $\endgroup$ – Jane Jan 14 '16 at 10:09
1
$\begingroup$

You can use Piecewise and set its default to an imaginary number so that nothing is plotted for default values.

ContourPlot[
 Piecewise[{{
    Im[x + I*y - Log[x + I*y]],
    Re[x + I*y - Log[x + I*y]] > 0}}, I],
 {x, -6, 8}, {y, -6, 6},
 PlotPoints -> 75,
 Contours -> 16,
 ColorFunction -> "TemperatureMap"]

enter image description here

Or you can restrict the plot to a region

reg = DiscretizeRegion@ImplicitRegion[Re[x + I*y - Log[x + I*y]] > 0,
    {{x, -6, 8}, {y, -6, 6}}];

ContourPlot[
 Im[x + I*y - Log[x + I*y]],
 {x, y} ∈ reg,
 Contours -> 16,
 PlotPoints -> 75,
 ColorFunction -> "TemperatureMap"]

enter image description here

For comparison purposes,

Plot3D[Im[x + I*y - Log[x + I*y]],
 {x, y} ∈ reg,
 ColorFunction -> Function[{x, y, z},
   ColorData["TemperatureMap"][z]]]

enter image description here

$\endgroup$
0
$\begingroup$

You can also use RegionPlot

f = x + I*y - Log[x + I*y];

RegionPlot[Im@f != 0 && Re@f > 0, {x, -6, 8}, {y, -6, 6}]

enter image description here

$\endgroup$
1
  • $\begingroup$ That doesn't plot the imagery part of the function, as specified in the question. $\endgroup$ – David G. Stork Jan 13 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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