Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2 years ago

Juanjo gravatar image

To complement the answer by @achrzesz, let us point out two additional approaches to fill exactly the region between the curves y=f(x) and y=g(x) where f(x)g(x), with x in a given interval [a,b], that is, the region
{(x,y)R2axb, f(x)yg(x)}. First method:

f(x) = sin(2*x+3)
g(x) = 2*cos(2*x+2)
pf = plot(f(x), (x,-3,3), color="red", fill=max_symbolic(f(x),g(x)), fillcolor="lightgreen")
pg = plot(g(x), (x,-3,3), color="blue")
show(pf+pg)

Second method:

var("x,y")
p = plot([f(x),g(x)], (x,-3,3), color=["red","blue"])
r = region_plot([f(x)<y, y<g(x)], (x,-3,3), (y,-2,2), incol="lightgreen", plot_points=[100,100])
show(r+p)

See this SageMath Cell

click to hide/show revision 2
No.2 Revision

To complement the answer by @achrzesz, let us point out two additional approaches to fill exactly the region between the curves y=f(x) and y=g(x) where f(x)g(x), with x in a given interval [a,b], that is, the region
{(x,y)R2axb, f(x)yg(x)}. First method:

f(x) = sin(2*x+3)
g(x) = 2*cos(2*x+2)
pf = plot(f(x), (x,-3,3), color="red", fill=max_symbolic(f(x),g(x)), fillcolor="lightgreen")
pg = plot(g(x), (x,-3,3), color="blue")
show(pf+pg)

Second method:

var("x,y")
p = plot([f(x),g(x)], (x,-3,3), color=["red","blue"])
r = region_plot([f(x)<y, y<g(x)], (x,-3,3), (y,-2,2),  incol="lightgreen", plot_points=[100,100])
show(r+p)

See this SageMath Cell

click to hide/show revision 3
No.3 Revision

To complement the answer by @achrzesz, let us point out two additional approaches to fill exactly the region between the curves y=f(x) and y=g(x) where f(x)g(x), with x in a given interval [a,b], that is, the region
{(x,y)R2axb, f(x)yg(x)}. First method:

f(x) = sin(2*x+3)
g(x) = 2*cos(2*x+2)
pf = plot(f(x), (x,-3,3), color="red", fill=max_symbolic(f(x),g(x)),  fillcolor="lightgreen")
pg = plot(g(x), (x,-3,3), color="blue")
show(pf+pg)

Second method:

var("x,y")
p = plot([f(x),g(x)], (x,-3,3), color=["red","blue"])
r = region_plot([f(x)<y, y<g(x)], (x,-3,3), (y,-2,2), 
                 incol="lightgreen", plot_points=[100,100])
show(r+p)

See this SageMath Cell