Skip to content

Shading the solution of quadratic inequality

4 messages · AbouEl-Makarim Aboueissa, R. Michael Weylandt, Randall Pruim

#
You should probably say more about which graphics engine you are
using, but here's a start:

curve(x^2-4, from = -3, to = 3)
x <- seq(-3, 3, length.out = 200)
polygon(c(x, rev(x)), c(x^2-4, rep(Inf, length(x))), col = 2)

The red is a little "oppressive" so I'd try to add transparency if
your device supports it. Adding a shade above/below argument to curve
based on the same principles might be a fun exercise too...

Michael

On Thu, Feb 16, 2012 at 9:13 AM, AbouEl-Makarim Aboueissa
<aaboueissa at usm.maine.edu> wrote:
#
I'm not sure exactly what sort of plot was desired, but I'll offer 1.5  
possibilities.

Currently you can do something like this:

require(mosaic)
plotFun( x^2 - 4 ~ x , xlim=c(-6,6), col='blue' )
plotFun( (x^2 - 4)/as.numeric(x^2 -4 > 0) ~ x , xlim=c(-6,-2),  
add=TRUE, col='blue', lwd=4 )

It is a bit of kludge since I'm using division by 0 to hide part of  
the function.  You can adjust colors, line thickness, and alpha to  
your particular sensitivities.  And you can use type='h' if you want a  
"filled in version".

Soon, you should be able to do

plofFun( x^2 - 4 ~ x, groups=(x^2-4>0) )

If you find yourself wanting to plot "mathematical" functions like  
this, I encourage you to give plotFun() a try and let us know how you  
like it.

---rjp
On Feb 16, 2012, at 9:42 AM, R. Michael Weylandt wrote:

            
#
The xlim=c(-6,-2) is extraneous in the code below.  It snuck in from  
something else I was doing.  It doesn't hurt any, but it doesn't do  
anything either since the plotting limits are inferred from the  
surrounding plot when add=TRUE is used.
On Feb 16, 2012, at 10:07 AM, Randall Pruim wrote: