Mathematica Asked on March 3, 2021
The 2nd term results in a divide-by-0 when x=0 unless y=0 also. The curve should go to Pi/2 for x=0 but it doesn’t. Running on MMA12 on Mac OS/X 64-bit (latest)
Help.
ContourPlot[
Tan[Sqrt[(y Exp[x/2])^2 - (x/2)^2]] - (
2 Sqrt[(y Exp[x/2])^2 - (x/2)^2])/x == 0, {x, -1, 0}, {y , 0, 4},
ContourStyle -> Red]
As suggested by J.M., use a higher value of PlotPoints
Clear["Global`*"]
f[x_, y_] =
Tan[Sqrt[(y Exp[x/2])^2 - (x/2)^2]] - (2 Sqrt[(y Exp[x/2])^2 - (x/2)^2])/x;
ContourPlot[f[x, y], {x, -1, 0}, {y, 0, 4},
ContourStyle -> Red,
PlotPoints -> 100,
Exclusions -> {f[x, y] == 0},
ExclusionsStyle -> Blue,
PlotLegends -> Automatic,
Epilog -> {Green, AbsolutePointSize[3], Point[{0, Pi/2}]}]
EDIT: For just the 0
contour
ContourPlot[f[x, y],
{x, -1, 0}, {y, 0, 4},
Contours -> {0},
ContourStyle -> Red,
ContourShading -> None,
Exclusions -> {f[x, y] == 0},
ExclusionsStyle -> Red,
PlotPoints -> 100,
Epilog -> {Green, AbsolutePointSize[3], Point[{0, Pi/2}]}]
EDIT 2: There are multiple solutions. The thin line is the implied zero in the gap separating the positive and negative contours.
pts = (Thread[{#, y /. NSolve[{f[#, y] == 0, 0 < y < 4}, y,
WorkingPrecision -> 50]}] & /@ Range[-19/20, -1/20, 1/20]) //
Flatten[#, 1] &;
ContourPlot[f[x, y], {x, -1, 0}, {y, 0, 4},
Contours -> {0},
ContourStyle -> Red,
ContourShading -> None,
Exclusions -> {f[x, y] == 0},
ExclusionsStyle -> Red,
PlotPoints -> 100,
Epilog -> {AbsolutePointSize[4], Green, Point[{0, Pi/2}],
Blue, Point[pts]}]
Answered by Bob Hanlon on March 3, 2021
ContourPlot
is the usual and usually easiest way to plot an implicit equation. But it's a rough tool and not suited to every problem. In such cases, sometimes using NDSolve
to integrate the differentiated equation works, as in the OP's case. In this case there are two solution curves, one of which seems of no interest to the OP. It is the boundary of the domain Sqrt[(y Exp[x/2])^2 - (x/2)^2] == 0
or more simply y == 1/2 Sqrt[E^-x x^2]
. Both the desired curve (in red) and the boundary (in plot-blue) are shown below.
ClearAll[implCurve];
implCurve[f_, y_, {x_, a_, b_}, {x0_, y0_},
opts : OptionsPattern[ListLinePlot]] := First@ListLinePlot[
NDSolveValue[{y'[
x] == -Divide @@ Identity[D[f, {{x, y}}] /. y :> y[x]],
y[x0] == y0,
WhenEvent[x < a + (b - a)/10^4, "StopIntegration"],
WhenEvent[x > b - (b - a)/10^4, "StopIntegration"]},
y, {x, a, b}],
opts];
f[x_, y_] =
Tan[Sqrt[(y Exp[x/2])^2 - (x/
2)^2]] - (2 Sqrt[(y Exp[x/2])^2 - (x/2)^2])/x;
Plot[Evaluate@ (* returns 1/2 Sqrt[E^-x x^2] *)
Cases[f[x, y],
Sqrt[e_] :>
Return[y /. Normal@Solve[e == 0 && y > 0 && x < 0, y, Reals],
Cases], Infinity], {x, -1, 0},
Epilog -> {Green, AbsolutePointSize[3], Point[{0, Pi/2}],
implCurve[f[x, y], y, {x, -1, 0}, {-1/2, #}, PlotStyle -> Red] & /@
Flatten@Values@NSolve[f[-1/2, y] == 0 && 3/2 < y < 4]},
PlotRange -> {{-1, 0}, {0, 4}}, Frame -> True,
PlotRangePadding -> Scaled[0.02], AspectRatio -> 1
]
Answered by Michael E2 on March 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP