Ask Your Question
0

How do I plot Asymptotes of a curve

asked 2020-02-21 07:40:48 -0500

Subham gravatar image

I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examples

edit retag flag offensive close merge delete

Comments

Could you give us an example of a curve you are trying to plot? There is an extensive documentation.

vdelecroix gravatar imagevdelecroix ( 2020-02-21 14:21:33 -0500 )edit

(3x^2-2x+1)/(x-1) I want slant asymptotes for this equation

Subham gravatar imageSubham ( 2020-02-23 03:39:21 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2020-02-21 21:06:34 -0500

dazedANDconfused gravatar image

Here's an example to illustrate some of the documentation:

f=x/(x^2-1)+1
p1 = plot(f,(-5,5), detect_poles='show',color='green', ymin=-10,ymax=10)
p2 = plot(1,(-5,5), color='red', linestyle='--')
show(p1+p2)

Run the code in a Sage Cell Server and you'll get: image description

The vertical asymptotes are done automatically with detect_poles='show' in plotting f. The result is put into p1. Since vertical asymptotes involve the function going off to plus or minus infinity, ymin=-10,ymax=10 sets the values to which the plot will go. The horizontal asymptotes are something you need to find; of course, SAGE can help. There is one horizontal asymptote and I've put its plot in p2. Finally, I combine the 2 using show()

edit flag offensive delete link more

Comments

Thank you so much.

Subham gravatar imageSubham ( 2020-02-23 00:39:25 -0500 )edit
1

answered 2020-02-22 18:25:44 -0500

Juanjo gravatar image

This is a follow up of @dazedANDonfused's answer to show how to plot all the asymptotes with the same style, that is, how to get the following figure:

image description

This can be achieved with the following modification of @dazedANDonfused's code:

f = x/(x^2-1)+1
p1 = plot(f,(-5,5), detect_poles='show',color='green', ymin=-10,ymax=10)
p2 = plot(1,(-5,5), color='red', linestyle='--')

for curve in p1:
    if len(curve)==2:
        opt = curve.options()
        opt["rgbcolor"] = "red"
        curve.set_options(opt)

show(p1+p2)

Please, note that p1 contains several lines (the vertical asymptotes and four arcs of the curve $y=f(x)$), each one having its own style and number of points. It can be seen as follows:

sage: print(p1)
Graphics object consisting of 6 graphics primitives
sage: for curve in p1:
....:     print(curve)    
Line defined by 233 points
Line defined by 2 points
Line defined by 162 points
Line defined by 152 points
Line defined by 2 points
Line defined by 214 points

Asymptotes are the only lines with two points. The loop added to @dazedANDonfused's code selects these lines and changes the item corresponding to color in the dictionary which contains the line options.

edit flag offensive delete link more

Comments

That's nice! I wasn't aware of how you could change the asymptote color.

dazedANDconfused gravatar imagedazedANDconfused ( 2020-02-22 19:18:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-02-21 07:40:48 -0500

Seen: 131 times

Last updated: Feb 22