Classroom Tips and Techniques: Shading between Curves, and Integrating Vectors Componentwise
Robert J. Lopez Emeritus Professor of Mathematics and Maple Fellow Maplesoft
Introduction
This month, we will provide a method for shading between two arbitrary curves, and will show how to integrate a vector componentwise. The first issue is a long-standing one in Maple. Maple can shade between a curve and the horizontal axis, but cannot easily provide shading between two curves. Over the years, a variety of methods have been proposed by different users, methods typically requiring special coding to implement. In Maple 11, the implicitplot command now supports the option filledregions = true/false, and we will show how this new option can be used to shade between curves.
Our second topic was the subject of a recent inquiry by a colleague I have know for many years. He's new to the use of the VectorCalculus package, and wanted to know how to integrate componentwise a vector in this package.
Initializations
Shading between Curves
Shading with the plot Command
Maple's plot command has long had the functionality of shading between a curve and the horizontal axis. However, it has never had the ability to shade between two arbitrary curves. Consider the curves defined by the functions
Figure 1 Shading between the graph of and the -axis
Unfortunately, provision was never made for displaying the curve in a color different from the color of the shading. To show the curve in black, for example, takes a superposition of the shaded and unshaded versions of the graph, as we see in Figure 2.
Figure 2 Graph of shaded between the curve and the -axis
In Figure 3, we show what happens if we include the graph of , along with shading between this curve and the -axis. Note the use of the transparency option, without which the pink shading would cover the cyan, making the cyan invisible.
Figure 3 Shaded graphs of and
Although the region between the bounding curves is shaded in pink, the image in Figure 3 suffers from the cyan shading between the graph of and the -axis. In Figure 4, we deal with this by shading the region under the graph of in white.
Figure 4 Shading between the graphs of and
Of course, the graphs of the curves themselves can be made visible by adding them to Figure 4. This is done in Figure 5.
Figure 5 Graphs of and with shading of the region between the curves
Shading with the implicitplot Command
The following remarks should clarify some aspects of the behavior of the implicitplot command.
The implicitplot command can be applied to an expression, an equation, or a single inequality.
As per Table 1, setting the filledregions option to true causes implicitplot to shade regions in the graph.
Rule 1
Expression
Region satisfying shaded one color; satisfying another.
Rule 2
Equation
All terms are moved to the left. Calling this left side the shading is as in Rule 1.
Rule 3
Inequality
Just the region satisfying the inequality is shaded.
Table 1 Rules governing the behavior of the filledregions option
These basic functionalities are illustrated in Figure 6, where the options
Figure 6 Rules in Table 1 are illustrated respectively in Figures 6(a), 6(b), and 6(c)
To extract from these basic functionalities the ability to shade between two arbitrary curves, write the function
where and are as defined in the previous section. Since the filledregions option will shade the region where in red and the region where in yellow, Figure 7 shows in red the region satisfying and . The first factor in is therefore negative; the second, positive. Hence, the region between the two curves is graph in red because on this region In the upper yellow region, because the inequalities and are both satisfied. In the lower yellow region, again because now the inequalities and
Figure 8 sets the colors to red and white so that just the region between the curves is shaded.
Figure 7 Shading between and via the device of plotting the product
Figure 8 The plot in Figure 7 with modified color scheme
Other Solutions
Here are two other ways to shade between two curves. The first is the command FillBetweenCurves generated by the following Maple code. It was written by one of the Maple programmers in response to my constant badgering for a complete solution to the the problem of shading between two curves. It's not built into Maple because it is as yet only a partial solution to the problem.
An example of its use is provided by Figure 9.
Figure 9 Shading between and via FillBetweenCurves command
On obvious shortcoming of this FillBetweenCurves command is that the curves are colored with the same color as the shading.
A second solution is provided by the inequalityplot command in the InequalityGraphics package written by Robert Ipanaqu? Chero, available from the Maple Applications Center (InequalityGraphics), and described in the Maple Reporter article A Package for Graphing Solution Sets of Nonlinear Inequalities, also available from the Maple Applications Center (Reporter Article). The interested reader can follow these links to download the articles and the additional Maple code.
Integrating a Vector Componentwise
For a user moving only now from implementing vector calculus with the old linalg package to implementing it with the newer VectorCalculus package, there are many differences to consider. One difference is how the operations of differentiation and integration are redefined so that they act immediately on objects, and do not have to be mapped onto them as in the old linalg package.
Just recently, a colleague I've known for many years began the transition to VectorCalculus. I received the following question from him soon after.
How can the vector
be integrated componentwise in the VectorCalculus package? In the VectorCalculus package, differentiate this vector with
The action of the diff command is immediate, and does not require the older syntax
As with diff, the int command is also immediate in the VectorCalculus package, but integration requires a bit more care. If we issue the command
the integration is indeed immediate. But what if we want the unevaluated definite integral? This is indeed what my colleague wanted, because ultimately, the vectors he was integrating required numeric integration. The unevaluated integral in the VectorCalculus package is obtained with the int command, not the Int command.
This violation of the top-level paradigm of int for immediate integration, and Int for delayed, is a consequence of the additional functionality given int in the VectorCalculus package, where iterated integration, and integration over predefined domains are both supported. Details and examples are available on the help page for VectorCalculus,int.
Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.