Ask Your Question

Graph or plot a system of inequalities

asked 2015-09-24 14:34:10 +0200

mellow_yellow gravatar image

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 (, it seems like I need a region plot, but I'm not sure.

image description

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-09-24 16:25:08 +0200

calc314 gravatar image

Here is another option:

show(p,axes=True,frame=False )
edit flag offensive delete link 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)
mellow_yellow gravatar imagemellow_yellow ( 2015-09-24 17:47:48 +0200 )edit

answered 2015-09-24 16:20:05 +0200

ndomes gravatar image

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)
edit flag offensive delete link 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.

mellow_yellow gravatar imagemellow_yellow ( 2015-09-24 17:49:42 +0200 )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

1 follower


Asked: 2015-09-24 14:34:10 +0200

Seen: 2,832 times

Last updated: Sep 24 '15