Message Boards Message Boards

0
|
3764 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Plot asymptote on graph

Posted 4 years ago

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 nowenter image description here

Plot[{(2 x^2 - 9)/Sqrt[x^2 - 1]}, {x, -13, 13}, AxesLabel -> {X, Y}, 
 GridLines -> {{1}, None}]

enter image description here

POSTED BY: Semen Pampam
4 Replies

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}]

enter image description here

POSTED BY: Henrik Schachner

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}]
POSTED BY: Gianluca Gorni
Posted 4 years ago

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]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 4 years ago

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.

POSTED BY: Semen Pampam
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract