# How to make plot of implicit function?

I try to produce a plot of $$\frac{1}{2}-\left| y\right| =\sqrt{\left(\frac{1}{2}-\left| y\right| \right)^2+(y-\sin (x))^2}$$ through

ContourPlot[1/2 - Abs[y] ==Sqrt[(1/2 - Abs[y])^2+(y-Sin[x])^2],
{x,-Pi,  Pi}, {y, -1, 1}, PlotPoints -> 20]


, but I obtain an empty plot.

• @Bill: Are you serious? Thank you anyway. – user64494 May 25 '17 at 6:00
• Isn't this solvable algebraically? You just get $y=\sin x$ such that $-\frac{1}{2}\le y\le\frac{1}{2}$ – Ian Miller May 25 '17 at 7:49
• ParametricPlot[If[1/2 - Abs[Sin[x]] > 0, {x, Sin[x]}, {}], {x, -Pi, Pi}] – Coolwater May 25 '17 at 7:57
• @Ian Miller: Please, peresent an algebraic solution to base your words. – user64494 May 25 '17 at 7:59
• The underlying problem is that ContourPlot has a hard time plotting the contour of $f(x,y)=g(x,y)$ if the functions never cross each other, i.e. you always have $f(x,y)\le g(x,y)$ and never $f(x,y)>g(x,y)$. – user484 May 26 '17 at 4:22

ir = ImplicitRegion[
FullSimplify[
Reduce[{1/2 - Abs[y] ==
Sqrt[(1/2 - Abs[y])^2 + (y - Sin[x])^2], -Pi < x < Pi, -1 < y <
1}, {x, y}, Reals]], {x, y}]
RegionPlot[ir,
GridLines -> {{-Pi, -5 Pi/6, -Pi/6, Pi/6, 5 Pi/6, Pi}, None}]


This can be solved algebraically as follows:

$$\frac{1}{2}-\left| y\right| =\sqrt{\left(\frac{1}{2}-\left| y\right| \right)^2+(y-\sin (x))^2}$$

Firstly note that $\frac{1}{2}-|y|\ge0$ so $-\frac{1}{2}\le y\le\frac{1}{2}$.

Next square the equation:

$$\left(\frac{1}{2}-\left| y\right|\right)^2 =\left(\frac{1}{2}-\left| y\right| \right)^2+(y-\sin (x))^2$$

$$0=(y-\sin(x))^2$$

$$0=y-\sin(x)$$

$$y=\sin(x)$$

So the solution is $y=\sin(x)$ such that $-\frac{1}{2}\le y\le\frac{1}{2}$.

Using Mathematica's Solve or Reduce gives the same result (it just gives restrictions on $x$ rather than $y$).

Solve[{1/2 - Abs[y] == Sqrt[(1/2 - Abs[y])^2 + (y - Sin[x])^2], Element[y, Reals], Element[x, Reals]}, y]

{{y -> ConditionalExpression[Sin[x], (C[1] \[Element] Integers && 2 \[Pi] C[1] <= x <= 1/6 (\[Pi] + 12 \[Pi] C[1])) || (C[1] \[Element] Integers && \[Pi] + 2 \[Pi] C[1] < x <= 1/6 (7 \[Pi] + 12 \[Pi] C[1])) || (C[1] \[Element] Integers && 1/6 (-\[Pi] + 12 \[Pi] C[1]) <= x < 2 \[Pi] C[1]) || (C[1] \[Element] Integers && 1/6 (5 \[Pi] + 12 \[Pi] C[1]) <= x <= \[Pi] + 2 \[Pi] C[1])]}}

Reduce[{1/2 - Abs[y] == Sqrt[(1/2 - Abs[y])^2 + (y - Sin[x])^2], Element[y, Reals], Element[x, Reals]}, y]

C[1] \[Element] Integers && (((2 \[Pi] C[1] <= x <= 1/6 (\[Pi] + 12 \[Pi] C[1]) || 1/6 (5 \[Pi] + 12 \[Pi] C[1]) <= x <= \[Pi] + 2 \[Pi] C[1]) && y == Sin[ x]) || ((1/6 (-\[Pi] + 12 \[Pi] C[1]) <= x < 2 \[Pi] C[1] || \[Pi] + 2 \[Pi] C[1] < x <= 1/6 (7 \[Pi] + 12 \[Pi] C[1])) && y == Sin[x]))


Plotting the solution from the algebraic solution is then straightforward:

Plot[Sin[x] && Abs[Sin[x]] <= 1/2, {x, -Pi, Pi}]


• I think you meant Plot[ConditionalExpression[Sin[x], Abs[Sin[x]] <= 1/2], {x, 0, 2 π}]. – J. M.'s technical difficulties May 26 '17 at 3:38
• The notation I used worked for me in version 10.2. It produced a similar graph to ubpdqn's answer. I'll include it. – Ian Miller May 26 '17 at 3:44
• @Ian Miller: I find your answer made by hand with help of Mathematica. – user64494 May 26 '17 at 5:59

If you wonder why ContourPlot fails, notice that your two functions touch each other on discrete lines but never cross.

Plot3D[{1/2 - Abs[y],
Sqrt[(1/2 - Abs[y])^2 + (y - Sin[x])^2]}, {x, -Pi, Pi}, {y, -1, 1}]


ContourPlot looks for the difference in the functions to change signs, which it never does.

Knowing this you can get an approximation by plotting a countour line at some small epsilon near zero:

 ContourPlot[
1/2 - Abs[y] - Sqrt[(1/2 - Abs[y])^2 + (y - Sin[x])^2], {x, -Pi,
Pi}, {y, -1, 1}, PlotPoints -> 200, Contours -> {-0.0001},

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]

As for question, are you sure your equation even has a solution? If it has, then you should be able to find the roots using NSolve[] or Solve[].
• The plot under consideration is not empty. For example, $(0,0)$ and $(-\frac {\pi} 6, -\frac {1} 2)$ belong to the one. @SuTron – user64494 May 25 '17 at 7:30