# Display Y-intercept? 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 close merge delete

Sort by » oldest newest most voted

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.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.

more

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.rhs()
y0=80*x0
p3=point( (x0,y0), size=40)
p9=p1+p2+p3
show(p9)

more

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

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.

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

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

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.