Ask Your Question
0

Display Y-intercept?

asked 2013-06-23 21:06:51 +0100

bxdin gravatar image

updated 2015-01-14 14:44:11 +0100

FrédéricC gravatar image

I was able to successfully compute the following with Sage 5.9:

p1 = plot(20*x + 10000, -8,600, ymin = -15, ymax = 30000)
p2 = plot(80*x, -8,600, ymin = -15, ymax = 30000, color = 'orange')
p9 = (p1 + p2)
plot(p9)

Is it possible for me to get Sage to display the point of intersection between the 2 lines?

The intersection occurs at 166 of the x-axis, with a y value of around 13300.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2013-06-29 12:44:17 +0100

dazedANDconfused gravatar image

updated 2013-06-29 12:54:53 +0100

Here's the code I was trying to indicate in my comment plus a little bit extra to address your latest comments. It uses your code and calc314's code. Since you said you wanted it to display the answer, 166.66 you have asked for just the x-value.

p1 = plot(20*x + 10000, -8,600, ymin = -15, ymax = 30000)
p2 = plot(80*x, -8,600, ymin = -15, ymax = 30000, color = 'orange')
p9 = (p1 + p2)
ans=solve(20*x+10000==80*x,x)
x0=ans[0].rhs()
y0=80*x0
p3=point( (x0,y0), size=40)
p4=text('%s'%x0,(x0+30,y0-1000)) 
p5=text('(%s,%s)'%(x0,y0),(x0+30,y0-3000))
p9=p1+p2+p3+p4+p5
show(p9)
print 'x value of intersection', x0
print 'x value of intersection', n(x0,digits=5)

You can, of course, remove the line p5=text('(%s,%s)'%(x0,y0),(x0+30,y0-3000)) and pick the print statement you like best.

edit flag offensive delete link more
1

answered 2013-06-23 23:05:59 +0100

calc314 gravatar image

You can solve this by hand and plot or by Sage and plot as follows:

ans=solve(20*x+10000==80*x,x)
x0=ans[0].rhs()
y0=80*x0
p3=point( (x0,y0), size=40)
p9=p1+p2+p3
show(p9)
edit flag offensive delete link more

Comments

So there's no way to get Sage to display, 166.66, as the answer?

bxdin gravatar imagebxdin ( 2013-06-24 20:22:57 +0100 )edit

I'm not sure what you're asking. To calc314's additional code can add the line: print x0 and it will display 500/3 below the graph. If you want it displayed on the graph you could add: p4=text('%s'%x0,(x0+30,y0-1000)) to print the coordinates of the point on the graph; just change the line to p9=p1+p2+p3+p4. I had to adjust where it printed [eg y0-1000] because the text came out over the point; I don't know if there's a way to get around that.

dazedANDconfused gravatar imagedazedANDconfused ( 2013-06-27 13:14:45 +0100 )edit

Ah, I might have miss interpreted your question. @dazedANDconfused is correct. Just use `print x0,y0` to get the coordinates of the intersection point.

calc314 gravatar imagecalc314 ( 2013-06-27 15:42:27 +0100 )edit

I did the following: p1 = plot (2*x/3 - 1, -10,10, ymin=-10, ymax=10) p2 = plot (4*x/24 - 1/24, -10,10, ymin=-10, ymax=10, color = 'green') plot(p1 + p2) print(x0,y0) I got the following error message instead, even without the parentheses on the print statement.: Traceback (click to the left of this block for traceback) ... NameError: name 'x0' is not defined

bxdin gravatar imagebxdin ( 2013-06-29 07:54:37 +0100 )edit

You did not define x0 or y0. Until these are defined Sage does not know what they are. You need to update and use the first three lines of my answer above.

calc314 gravatar imagecalc314 ( 2013-06-29 08:43:07 +0100 )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: 2013-06-23 21:06:51 +0100

Seen: 1,825 times

Last updated: Jun 29 '13