tetyushins
(Semen Pampam)
February 8, 2021, 1:03pm
1
Is it possible to plot an asymptote via a command? I have a function, I plotted it, but there is a problem with the asymptotes, how to plot them? I did a search but it was not unsuccessful. 1 screenshot is how my graph should look like, and 2 screenshot is where I am now
Plot[{(2 x^2 - 9)/Sqrt[x^2 - 1]}, {x, -13, 13}, AxesLabel -> {X, Y},
GridLines -> {{1}, None}]
Hi Semen
exp = (2 x^2 - 9)/Sqrt[x^2 - 1];
asymptotes = ResourceFunction["Asymptotes"][exp, x, y]
(* <|"Vertical" -> {{y -> -∞, x -> ±1}},
"Oblique" -> {{y -> -2 x, x -> -∞}, {y -> 2 x, x -> ∞}}|> *)
If you have to do this for many plots, I would write some code to generate line endpoints from asymptotes. Here I just did it manually
epilog = {Dashed, Darker[Green], InfiniteLine[{{-1, -1}, {-1, 1}}],
InfiniteLine[{{1, -1}, {1, 1}}], Red, InfiniteLine[{{-1, -2}, {0, 0}}]}
Plot[exp, {x, -13, 13}, AxesLabel -> {"X", "Y"}, Epilog -> epilog]
tetyushins
(Semen Pampam)
February 8, 2021, 4:16pm
3
Thanks for the help, I’m new to this and found little information for the graphs. I thought there was a special team that draws everything at once.
You could ask the developer to provide the functionality directly. Here is an attempt to do it automatically:
exp = (2 x^2 - 9)/Sqrt[x^2 - 1];
{asymptotesObl, asymptotesVert, asymptotesHor} =
Table[ResourceFunction["Asymptotes"][exp, x, y, type],
{type, {"Oblique", "Vertical", "Horizontal"}}];
asymptotesPrimitives = {If[asymptotesObl == {}, Nothing,
InfiniteLine[{0, 0}, {x, y}] /. asymptotesObl[[All, {1}]] /.
x -> 1],
If[asymptotesVert == {}, Nothing,
InfiniteLine[{x, 0}, {0,
1}] /.
(asymptotesVert[[All, {2}]] /.
{x -> \
\[PlusMinus]val_} :>
Splice[{{x -> -val}, {x -> val}}])],
If[asymptotesHor == {}, Nothing,
InfiniteLine[{0, y}, {1, 0}] /. asymptotesHor]};
Plot[exp, {x, -13, 13}, Epilog -> {asymptotesPrimitives}]
Hi, here is another - short and simple - approach:
func = (2 x^2 - 9)/Sqrt[x^2 - 1];
asympt = Asymptotic[func, x -> Infinity];
Plot[{func, asympt}, {x, -13, 13}, AxesLabel -> {"X", "Y"}, GridLines -> {{1}, None}, PlotStyle -> {Automatic, Dashed}]