Ask Your Question

how to correctly plot 1/(x-3)

asked 2011-12-15 22:12:52 -0600

Amit Kumar gravatar image

I have to plot 1/(x-3). clearly the function is not defined at x=3. Whenever I try to plot it there is a huge vertical line at x=3, which should not be there. Help me out.

The code I write sage: f(x)=1/(x-3) sage: p=plot(f(x),(x,-10,10) sage:

Thanks Amit

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted

answered 2011-12-16 02:44:41 -0600

Jason Grout gravatar image

updated 2011-12-16 02:45:59 -0600

You can also use the detect_poles option to not draw the vertical line

plot(1/(x-3),(x,0,5), detect_poles=True,ymin=-2,ymax=2)

Or even better, have it automatically draw the asymptote:

plot(1/(x-3),(x,0,5), detect_poles='show',ymin=-2,ymax=2)
edit flag offensive delete link more

answered 2011-12-15 23:45:38 -0600

Use a plot range in show, ymax=2)

edit flag offensive delete link more

answered 2011-12-16 21:27:29 -0600

Amit Kumar gravatar image

Thanks Jason,tririver and Niles for the help.

especially Jason... Your method is with the least code and effective. Thanks

edit flag offensive delete link more


You're welcome :) If you want, you can click the check mark to "accept" Jason's answer.

niles gravatar imageniles ( 2011-12-17 15:31:49 -0600 )edit

answered 2011-12-15 23:39:37 -0600

niles gravatar image

In Sage you can add separate plots to draw them on the same image; try this:

sage: f(x)=1/(x-3)
sage: p=plot(f(x),(x,-10,2.9), aspect_ratio=1)
sage: q=plot(f(x),(x,3.1,10), aspect_ratio=1)
sage: (p+q).show()

or, if you want to be a little fancy, add the asymptote:

sage: L = line2d([(3,10),(3,-10)], linestyle="dashed", color="red")
sage: (p+q+L).show()
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2011-12-15 22:12:52 -0600

Seen: 306 times

Last updated: Dec 16 '11