# Graph or plot a system of inequalities

Disclaimer: I'm somewhat new to Sage.

Is it possible to graph a system of inequalities in Sage? I'd like to reproduce the following system (top of image) and its graph (bottom of image). Based on (http://www.sagemath.org/tour-graphics...), it seems like I need a region plot, but I'm not sure.

edit retag close merge delete

Sort by ยป oldest newest most voted

Here is another option:

var('y')
p=region_plot([y>=x-3,x>=y^2+2*y-3],(x,-10,20),(y,-8,10))
p+=implicit_plot(x==y^2+2*y-3,(x,-10,20),(y,-8,10),color='black')
p+=plot(x-3,(x,-10,20),color='black')
show(p,axes=True,frame=False )

more

You beat me to it. I was going to suggest:

var("x y")

f1 = x >= y^2 + 2*y -3
f2 = y >= x-3
f3 = x == y^2 + 2*y -3
f4 = y == x-3

rx = (-10,15)
ry = rx

i = [f1, f2] # i meaning inequalities

p = region_plot(i, rx, ry)
p+= implicit_plot(f3, rx, ry, color="black")
p+= implicit_plot(f4, rx, ry, color="black")

show(p, axes="true", frame=False, aspect_ratio=1)

( 2015-09-24 10:47:48 -0500 )edit

To get a plot in your case:

g(x) = x-3
y = var('y')
eq = x == y^2 + 2*y -3
sol = solve(eq,y)
h1(x) = sol[0].rhs()
h2(x) = sol[1].rhs()

G = Graphics()
G += plot(g,-5,5, fill=g(5),fillcolor='gold')
G += plot(h1,-4,5)
G += plot(h2,-4,5,fill=h1,fillcolor='blue',fillalpha=0.2)
G.show()

more

This is a clever solution. I didn't know you could use the solver with rhs and plot to graph relations. The problem is that it doesn't shade the inequality's region like region_plot does.

( 2015-09-24 10:49:42 -0500 )edit