Ask Your Question
0

Graph or plot a system of inequalities

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

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 (http://www.sagemath.org/tour-graphics...), 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
2

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

calc314 gravatar image

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

Comments

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 +0100 )edit
1

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

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)
G.show()
edit flag offensive delete link more

Comments

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

1 follower

Stats

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

Seen: 3,001 times

Last updated: Sep 24 '15