Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have an implicit function expression

F[x, y] := 
  -E^(-2 a) (-1 + (c (1 - 1/y^2))/a) 
    (-1 + (b (1 - 1/y^2))/(2 a)) + (1 + (c (1 - 1/y^2))/a) (1 + (b (1 - 1/y^2))/(2 a))

where

a = Sqrt[x^2 - (1 - 1/y^2) y^2]

b = Sqrt[x^2 - 2 y^2]

c = Sqrt[x^2 - y^2]

I plot the expression F[x, y] == 0 with ContourPlot, and I get something like this:

I need to obtain a plot like this:

If I try to plot Re[F[x,y]]==0 and the result looks like this: enter image description here

But there is one more solution(branch in the left) that I don't need. How can I separate there solutions?

share|improve this question
    
I used completely the same plotting function as whuber in answer below: ContourPlot[F[x, y] == 0, {x, 0, 5}, {y, 0, 1}, ContourStyle -> Thick] ] –  Gretchen Feb 17 '13 at 8:05
    
Since you like huber's solution so much, I suggest you accept it. Just click on the check mark underneath the current vote total for the answer. This will give both of you some extra points. –  m_goldberg Feb 18 '13 at 7:26

2 Answers 2

up vote 13 down vote accepted

The plot is correct: the dashed line lies outside the domain of definition of the function.

Let's first clean up the syntax. Capitalized names are reserved and you ought to delay evaluation using := instead of =. It's also a good idea to make a, b, and c local:

g[x_, y_] := 
  With[{a = Sqrt[x^2 - (1 - 1/y^2) y^2], b = Sqrt[x^2 - 2 y^2], c = Sqrt[x^2 - y^2]}, 
  -E^(-2 a) (-1 + (c (1 - 1/y^2))/a) 
     (-1 + (b (1 - 1/y^2))/(2 a)) + (1 + (c (1 - 1/y^2))/a) (1 + (b (1 - 1/y^2))/(2 a))];

The square roots can cause a problem: when their arguments are negative, g might not have a real value, and when their arguments are zero, g can be undefined (due to zeros in the denominators). One automatic way to check is to look for all roots in the definition of g, collect them, and plot the region where they are simultaneously non-negative:

Show[
 RegionPlot[
  And @@ Union[Last[Last[Reap[g[x, y] /. Sqrt[z__] :> Sow[z >= 0]]]]] // Evaluate, 
   {x, 0, 5}, {y, 0, 1}],
 ContourPlot[g[x, y] == 0, {x, 0, 5}, {y, 0, 1}, ContourStyle -> Thick]
 ]

Contour and region plot

With a similar technique--use Together // Denominator to extract just the bottom of g after expressing it as a fraction--you can verify that g[x,y] is singular along the left boundary of this region. Thus the zero contour should not include the dashed line in the question.


Response to the Edit

To separate the branches, you can use @Jens' solution along with the RegionFunction defined here: its negation selects the other branch. Because we will need it twice, let's compute this function once and for all:

rf[x_, y_] := 
  Evaluate[And @@ Union[Last[Last[Reap[g[x, y] /. Sqrt[w__] :> Sow[w >= 0]]]]] // FullSimplify]

Here are the two plots (with MaxRecursion increased in the second one to show more detail near the origin):

Show[ContourPlot[Re[g[x, y]] == 0, {x, -2, 2}, {y, 0, 3/4}, 
  ContourStyle -> {Thick, Darker[Blue], Dashed},  
  RegionFunction -> Function[{x, y, z}, rf[x, y]]], 
 ContourPlot[Re[g[x, y]] == 0, {x, -1, 1}, {y, 0, 3/4}, 
  ContourStyle -> {Thick, Darker[Red]},  MaxRecursion -> 5, 
  RegionFunction -> Function[{x, y, z}, ! rf[x, y]]]]

Zoomed plots

share|improve this answer
    
Thank you so much! You showed me how to work with domains of definition of functions! I'm so happy, because if ypu didn't, it would be my next question here! :) About solution: you're right about everything, but it seems like I didn't ask my question correctly. I'm sorry! My only aim was to catch that branch that could be caused because both or one of arguments are complex. –  Gretchen Feb 17 '13 at 8:09
    
Also if the arguments are both complex or even one of them is the function can have real values. In your code you assume that both of them are real, right? –  Gretchen Feb 17 '13 at 18:33
    
Yes, because your question implicitly supposed everything is real (otherwise the contour plot would not make much sense). –  whuber Feb 17 '13 at 21:42
    
Thank you so much! Your answer was extremely useful to me! Thanks again! :) –  Gretchen Feb 18 '13 at 12:47

From the sketch in the question, one could also surmise that the goal is to take the real part of the function. In that case, after correcting the definition of F, I would get this:

With[{
  a = Sqrt[x^2 - (1 - 1/y^2) y^2], b = Sqrt[x^2 - 2 y^2], 
  c = Sqrt[x^2 - y^2]
  },

 F[x_, y_] := -E^(-2 a) (-1 + (c (1 - 1/y^2))/a)
    (-1 + (b (1 - 1/y^2))/(2 a)) + (1 + (c (1 - 1/y^2))/
       a) (1 + (b (1 - 1/y^2))/(2 a))
 ]

ContourPlot[Re[F[x, y]] == 0, {x, 0, 5}, {y, 0, 1}, PlotPoints -> 100]

real part

share|improve this answer
    
Thank you, but I tried to do this already! The question is exactly how to separate that left branch that appears, because I don't need it. –  Gretchen Feb 17 '13 at 8:57
    
You should have revealed that information in the question earlier. –  Jens Feb 17 '13 at 18:58
    
The fact that I tried this way didn't help me with problem. I should write that. I'm so sorry! –  Gretchen Feb 17 '13 at 19:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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