Application Center - Maplesoft

Classroom Tips and Techniques: A Package for Graphing Solution Sets of Nonlinear Inequalities

You can switch back to the summary page by clicking here.

Classroom Tips and Techniques:
A Package for Graphing Solution Sets of Nonlinear Inequalities

Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow

? Maplesoft, a division of Waterloo Maple Inc., 2006

Introduction

Maple's inequal command in the plots package will graph the feasible region for a set of linear inequalities.  Even though Maple's solve command can solve some nonlinear inequalities exactly, Maple does not have specific tools for graphing solution sets of nonlinear inequalities.  As we show in Example 6, the contourplot command (or even the plot3d command) can be used to graph the feasible region for an inequality of the form  Considerably more effort must be exerted to graph the points satisfying several such inequalities.  And although Maple can shade the region between a curve and the horizontal axis, it cannot easily shade the region between two arbitrary curves.

In October 2005 the Maple Applications Center (www.mapleapps.com) acquired

 A Maple Package for Solving and Displaying Inequalities  Robert Ipanaqu? Chero National University of Piura http://www.unp.edu.pe/pers/ripanaque E-mail: robertchero@hotmail.com

an application that addresses several of these Maple shortcomings.

You may view the original application here:

By example, some taken from the author's work itself, this month's column will illustrate the user-contributed
InequalityGraphics package and its applicability to classroom tasks.  This package provides two commands, namely, inequalityplot and complexinequalityplot.

The inequalityplot command will graph the two-dimensional feasible region for a set of nonlinear inequalities in two variables, that is, inequalities of the form  Consequently, by plotting the solution set of the inequalities < and the region between arbitrary plane curves can be shaded.

The complexinequalityplot command will plot the solution set of one or more inequalities of the form where is a real-valued function and the functions are complex-valued functions of the complex variable  In essence, however, the inequality is nothing more than because of the definition of .

 excludedcolor = colorname Color of the non-feasible region feasiblecolor = colorname Color of the feasible region linespoints = positive integer Number of points plotted along curves separating feasible and non-feasible regions feasiblepoints = positive integer Number of points computed inside feasible region thickness = positive integer Thickness of curves separating feasible and non-feasible regions color = colorname Color of curves separating feasible and non-feasible regions Table 1   Options for the inequalityplot and complexinequalityplot commands in the InequalityGraphics package

To make it easier for perusing the functionality of the package, a working version of the the code for the InequalityGraphics package is embedded in Initializations section, below.  Too often the process of installing a third-party package is a hurdle that prevents a user from trying out the new commands.  The downloaded code for the package (www.mapleapps.com), contains the three files applications.hdb, applications.ind, and applications.lib.  Dropping these files into the LIB folder of a Maple 10 installation will give permanent access to the package.  The name "applications" can be changed to something more meaningful, like InequalityGraphics, with no ill effects.  The ".ind" and ".lib" files provide the mathematical functionality of the package, whereas the ".hdb" file provides help pages without which the command of the package will still function.  The one help page provided by the hdb file can be accessed with the command ?inequals;  We leave these matters to the reader whose interest in the package is sufficiently sparked by this article.

The code available from the Application Center colors the non-feasible region white, by default, whereas the code embedded in this article colors it black. Hence, in this article we have  explicitly used the option excludedcolor = white.

Initializations

 > restart;

 > with(plots): interface(warnlevel=0):

 >

 > InequalityGraphics := module()    export  inequalityplot, complexinequalityplot;    option package; inequalityplot:=proc()  local ineq,ineqset,xx,yy,phaseSelection,phase1,phase2,phases,var1,        var2,xmin,xmax,ymin,ymax,dx,dy,jumpPrecision,        findJump,reg,c,p,x1,y1,p1List,p2List,aux1,aux2,jump1,        jump2,eq,cc,ops,fc,ec,ls,fb,fp,lp,llss;    if nargs<3 then    ERROR(`expecting 3 arguments, got 0.           This commmand also incorporates the options:            (1) exludedcolor=yellow,            (2) feasiblecolor=red,            (3) linespoints=350,            (4) feasiblepoints=15 and            (5) thickness=1.           Examples:            <1> inequalityplot(x^2+y^2<1,x=-1..1,y=-1..1),            <2> inequalityplot(x^2+y^2<1,x=-1..1,y=-1..1,                   excludedcolor=white,feasiblecolor=cyan)`)  fi:    ineq:=`if`(whattype(args[1])=set,convert(args[1],`and`),args[1]):  xx:=args[2]:yy:=args[3]:    if whattype(args[1])=set       then ineqset:=args[1]  elif whattype(ineq)=`<` or whattype(ineq)=`>` or       whattype(ineq)=`<=` or whattype(ineq)=`>=`       then ineqset:={ineq}  else ineqset:=convert(ineq,set)  fi:    var1:=lhs(xx):var2:=lhs(yy):    if not(depends(ineq,var1) and depends(ineq,var2)) then    ERROR(ineq,`doesn't depend on`,var1,`and`,var2)  fi:    ops:=[args[4..nargs]]:    if not hasoption(ops,feasiblecolor,fc,'ops')    then fc:=COLOR(RGB,.70,.70,1.0) fi:  if not hasoption(ops,excludedcolor,ec,'ops')    then ec:=COLOR(RGB,.20,.20,.20) fi:  if not hasoption(ops,feasiblepoints,fp,'ops')    then fp:=15 fi:  if not hasoption(ops,linespoints,lp,'ops')    then lp:=350 fi:    phaseSelection:=unapply(piecewise(ineq,1,2),var1,var2):  phase1:=(a,b)->1:phase2:=(a,b)->0:phases:=[phase1,phase2]:  xmin:=lhs(rhs(xx)):  xmax:=rhs(rhs(xx)):  ymin:=lhs(rhs(yy)):  ymax:=rhs(rhs(yy)):  dx:=(xmax-xmin)/(fp-1):  dy:=(ymax-ymin)/(fp-1):  jumpPrecision:=.02*min(dx,dy):  findJump:=(l,r)->   `if`(evalm((l-r)&*(l-r))  piecewise(    whattype(is)=`<` or whattype(is)=`>`,2,    whattype(is)=`<=` or whattype(is)=`>=`,1           ):  llss:=map(ls,[op(ineqset)]):    eq:=  `if`(whattype(ineqset)=set,       [seq(convert(ineqset[i],equality),i=1..nops(ineqset))],       [convert(ineq,equality)]      ):    cc:=[seq(implicitplot(eq[i],xx,yy,color=black,numpoints=lp),       i=1..nops(eq))]:  PLOT(op(reg),    seq(     CURVES(op(op(cc[i])[1]),LINESTYLE(llss[i])),i=1..nops(cc)),      op(convert(ops,PLOToptions)),    POLYGONS([[xmin,ymin],[xmin,ymax],[xmax,ymax],              [xmax,ymin],[xmin,ymin]],      op(convert(color=ec,PLOToptions))),  SCALING(CONSTRAINED),STYLE(PATCHNOGRID)):    end proc; complexinequalityplot:=proc()  local ineq,var,Revar,Imvar,ops;    if nargs<2 then    ERROR(`expecting 2 arguments, got 0.           This commmand also incorporates the options:            (1) exludedcolor=yellow,            (2) feasiblecolor=red,            (3) linespoints=350,            (4) feasiblepoints=15,            (5) linescolor=black and            (6) thickness=1.           Examples:            <1> complexinequalityplot(abs(z)<1,z=(-1..1,-1..1)),            <2> complexinequalityplot(abs(z)<1,z=(-1..1,-1..1),                   excludedcolor=white,feasiblecolor=cyan)`)  fi:  var:=lhs(args[2]):  Revar:=rhs(args[2])[1]:  Imvar:=rhs(args[2])[2]:  ineq:=subs(var=x+I*y,args[1]):  ops:=args[3..nargs]:    inequalityplot(ineq,x=Revar,y=Imvar,ops) end proc; end module:

 >

 > with(InequalityGraphics);

 >

Examples

Example 0

When working with the Laplace transform, the convolution product of and is defined by

=

The convolution of the functions

 (3.1.1)

and

 (3.1.2)

is difficult to obtain by the definition because of the complex nature of the implied conditionals in both  The integrand of the convolution integral

is nonzero on the solution set of the inequalities

 (3.1.3)

Figure 0.1, created with Maple's built-in inequal command from the plots package, displays this set in red.  (This command will graph only the solution set for linear inequalities.)

 >

Figure 0.1   In red, the solution set for {}

For each fixed , the integration is over the intersection of the line and the red parallelogram in Figure 0.1.  Thus, we have

a result extremely difficult to fathom without Figure 0.1.

Example 1

A graph of the solution set of the inequality

 (3.2.1)

drawn for the square appears in Figure 1.1.

Figure 1.1   Solution set of graphed in yellow

Example 2

A graph of the solution set of the inequalities

 (3.3.1)

and

 (3.3.2)

appears in Figure 2.1.

Figure 2.1   Solution set of {, } shown in gray

Example 3

A graph of the solution set of the inequalities

 (3.4.1)

 (3.4.2)

and

 (3.4.3)

appears in Figure 3.1.  Note that more than two inequalities are enclosed in set braces in the inequalityplot command.

 >

Figure 3.1   Solution set of s

Example 4

Figure 4.1 compares the solution sets of

and

the first on the left, the second on the right.

 >

 >

Figure 4.1   In gray, the solution set of in (a) and the solution set of in (b)

Example 5

The set of points that satisfy either

 (3.6.1)

 (3.6.2)

is graphed in Figure 5.1.

 >

Figure 5.1   Gray points satisfy either

Example 6

Drawn with the inequaltyplot command, Figure 6.1 shows the solution set of the inequality where is given by

 (3.7.1)

 >

Figure 6.1   Solution set for drawn in gray

 >

Figure 6.2, drawn with the plot3d command, shows the surface for  As such, it represents that part of the surface we can identify as being above the plane .  Rotating the graph so that it is viewed from a point sufficiently high on the -axis gives a sketch of the feasible region similar to Figure 6.1.

 >

 >

Figure 6.2   Graph of in (a); same graph rotated and viewed from above in (b)

 >

Figure 6.3, drawn with Maple's contourplot command, shows the graph of the curve determined by the equation .  This is the boundary inside or outside of which will be satisfied.

 >

Figure 6.3   Curve determined by solution of the equation

 >

The filled option in Maple's contourplot command shades in a specified color range according to the lowest and highest values along contours.  Figure 6.4 is a contour plot of in which the color range is from white to gray, with white being assigned to any contours on which the values of are lower than the one specified for the single contour to be drawn.  This specified contour value is zero, so any contour corresponding to a higher value will be shaded gray.

 >

 Figure 6.4 Shaded contour plot of  Black curve is the single contour  Gray designates where

Example 7

To shade the region between graphs of the curves and use the inequalityplot command as shown in Figure 7.1.  Note that an endpoint cannot be a symbol such as or .

 >

Figure 7.1   Region between and shaded gray

Example 8

Nonlinear inequalities actually arise in freshman calculus when students first meet a rigorous () definition of the limit:

 Formal Definition of Limit The real number is said to be the limit of at if, for any

At the heart of this definition is the inequality

that we would like to solve for .  For example, to show that solve the inequality

 (3.9.1)

for The solution set is shown in Figure 8.1 where is allowed to be both positive and negative.

 >

Figure 8.1   Solution set for the inequality shaded in gray

Although Maple cannot solve the inequality for it can solve the equation under the assumption that  The solutions, namely

 >

 (3.9.2)

 >

are graphed in Figure 8.2 where the colors indicate which solutions assume real values.  Compare Figure 8.2 to Figure 8.1.

 >

Figure 8.2   Graph of the analytic solution for

As with Example 6, the outline of the feasible region can be obtained with Maple's implicitplot command; the feasible region, with contourplot, as shown in Figure 8.3.

 >

 >

Figure 8.3   In (a), outline of feasible region via implicitplot; in (b), feasible region via contourplot

Surprisingly, the feasible region in Figure 8.1 is not symmetric.  Figure 8.4 shows the feasible region for much smaller values of and suggests the region might be more symmetric closer to .  In fact, it suggests that might be well approximated by a linear function.

 >

Figure 8.4   Solution set for the inequality for "small" values of

One way to find an approximation for when is small is to solve for a series solution about .  This can be done in Maple via

 >

 (3.9.3)

and

 >

 (3.9.4)

where we removed the absolute value function and created two equivalent equations.  In this case we obtained exact solutions and not the series expansions

 >

 (3.9.5)

and

 >

 (3.9.6)

This suggests a hypothesis tested in Figure 8.5 where the lines are drawn in green, is drawn in black, and is drawn in red.

 >

Figure 8.5   The lines in green, in black, and in red

Alternatively, we let Maple deduce

 >

 (3.9.7)

and

 >

 (3.9.8)

The function

 >

 (3.9.9)

 >

is continuous from the right at so that

The governing inequality is a graphical solution of which is seen in Figure 8.6.

 >

Figure 8.6   Shaded gray, the feasible region for the inequality

For the inequality is satisfied for any positive as Figure 8.6 suggests, and the following calculation shows.

 >

 (3.9.10)

Example 9

Drawn with the complexinequalityplot command, the solution set for the inequality

where , appears as the shaded region in Figure 9.1.

 >

Figure 9.1   Solution set for shaded in gray

The substitution

 (3.10.1)

 (3.10.2)

and hence, Figure 9.2 drawn with the inequalityplot command.

 >

Figure 9.2   Solution set for

The advantages of the complexinequalityplot command over the inequalityplot command for inequalities in the complex variable are obvious, and need no comment.

Example 10

Like the inequalityplot command, the complexinequalityplot command will graph the feasible region for a set of nonlinear complex inequalities.  For example, Figure 10.1 shows the set of points simultaneously satisfying the inequalities

 (3.11.1)

and

 (3.11.2)

 >

Figure 10.1   Solution set of shaded in gray

Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.