ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 23 Feb 2020 03:39:21 -0600How do I plot Asymptotes of a curvehttps://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/ I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examplesFri, 21 Feb 2020 07:40:48 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/Comment by Subham for <p>I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examples</p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50041#post-id-50041(3x^2-2x+1)/(x-1) I want slant asymptotes for this equationSun, 23 Feb 2020 03:39:21 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50041#post-id-50041Comment by vdelecroix for <p>I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examples</p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50018#post-id-50018Could you give us an example of a curve you are trying to plot? There is an [extensive documentation](http://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html).Fri, 21 Feb 2020 14:21:33 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50018#post-id-50018Answer by dazedANDconfused for <p>I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examples</p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?answer=50020#post-id-50020Here'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](https://sagecell.sagemath.org/) and you'll get:
![image description](/upfiles/15823402106383693.jpg)
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](https://ask.sagemath.org/question/10297/print-value-of-vertical-horizontal-asymptote/). There is one horizontal asymptote and I've put its plot in p2. Finally, I combine the 2 using `show()`Fri, 21 Feb 2020 21:06:34 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?answer=50020#post-id-50020Comment by Subham for <p>Here's an example to illustrate some of the documentation:</p>
<pre><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='--')
show(p1+p2)
</code></pre>
<p>Run the code in a <a href="https://sagecell.sagemath.org/">Sage Cell Server</a> and you'll get:
<img alt="image description" src="/upfiles/15823402106383693.jpg"></p>
<p>The vertical asymptotes are done automatically with <code>detect_poles='show'</code> in plotting f. The result is put into p1. Since vertical asymptotes involve the function going off to plus or minus infinity, <code>ymin=-10,ymax=10</code> sets the values to which the plot will go. The horizontal asymptotes are something you need to find; of course, <a href="https://ask.sagemath.org/question/10297/print-value-of-vertical-horizontal-asymptote/">SAGE can help</a>. There is one horizontal asymptote and I've put its plot in p2. Finally, I combine the 2 using <code>show()</code></p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50038#post-id-50038Thank you so much.Sun, 23 Feb 2020 00:39:25 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50038#post-id-50038Answer by Juanjo for <p>I wanna know the codes for plotting Asymptotes of any curve . I'll be so greatfull if anyone can help me with examples</p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?answer=50031#post-id-50031This 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](/upfiles/15824173637495372.png)
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. Sat, 22 Feb 2020 18:25:44 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?answer=50031#post-id-50031Comment by dazedANDconfused for <p>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:</p>
<p><img alt="image description" src="/upfiles/15824173637495372.png"></p>
<p>This can be achieved with the following modification of @dazedANDonfused's code:</p>
<pre><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)
</code></pre>
<p>Please, note that <code>p1</code> 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:</p>
<pre><code>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
</code></pre>
<p>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. </p>
https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50032#post-id-50032That's nice! I wasn't aware of how you could change the asymptote color.Sat, 22 Feb 2020 19:18:53 -0600https://ask.sagemath.org/question/50016/how-do-i-plot-asymptotes-of-a-curve/?comment=50032#post-id-50032