Application Center - Maplesoft

# Classroom Tips and Techniques: Gems from the Little Red Book of Maple Magic

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

Classroom Tips and Techniques:  Gems from the Little Red Book of Maple Magic

Robert J. Lopez

Emeritus Professor of Mathematics and Maple Fellow

Maplesoft

 Introduction Since coming to Maplesoft in 2003, I've kept a notebook of "gems" I've gleaned from consulting with the programmers in the building. I call it my "Little Red Book of Maple Magic." It really is red. The first spiral-bound notebook was red. When it overflowed, I moved the notes to a red ring-binder. But it's not so little any more.   This month, I thought I'd share a few recently recorded bits of this Maple magic.

Gem 1

Just the other day I needed to add a math expression to a graph that was to appear in a manual I'm updating. The code for the graph is in a table, and via the table-property dialog, the code can be hidden, but the graph displayed. This makes for an easy update to the graph in any future revision.

The math expression was , which I added to my graph with the textplot command from the plots package. In particular, I used  and the display command to merge the text onto the graph. Unfortunately, Maple immediately changes the expression to  and adds that to the graph.

OK, how do I prevent Maple from evaluating the expression? The suggestion I got was to convert the expression to an Atomic Identifier. This works!

But looking through my Little Red Book, I noted a similar problem. I wanted the legend on the graph of an inverse function to show . I tried using the plot option , but Maple again evaluated the expression and displayed . This time, the advice I got was a bit more complicated. The solution is shown in Table 1.

 > qx := Typesetting:-Typeset(q(x)): fnx := subs(Typesetting:-Typeset(q) = Typesetting:-Typeset(f^n),qx): f1x := subs(Typesetting:-Typeset(n) = Typesetting:-Typeset(-1),fnx): plot(x, x=0..1, legend = (f1x), color=black);

Table 1   Programmatically displaying  in the legend on a graph

Gem 2

From my earliest days of using Maple in the calculus classroom, I've always wanted Maple to return the derivatives of tangent, cotangent, hyperbolic tangent, and hyperbolic cotangent in the form that my students' textbooks were using. The Maple and textbook forms of these derivatives are listed in Table 2.

 Maple Typical Calculus Text Table 2   Certain derivatives in Maple and standard calculus texts

The reasoning behind Maple's choice of expressions for these derivatives is that they are "simpler;" that is, each rule involves just a single function, not two, as on the right in Table 2. When this was first "explained" to me years ago, I was also told that the rules could easily be modified. Well, just recently, someone showed me how to re-program Maple to do this. See Table 3. (The restart is in deference to any remember-table issues.)

 > restart; unprotect(`diff/tan`): unprotect(`diff(cot`): unprotect(`diff(tanh`): unprotect(`diff(coth`): `diff/tan`  := proc(a,x)  sec(a)^2*diff(a,x);end: `diff/cot`  := proc(a,x) -csc(a)^2*diff(a,x);end: `diff/tanh` := proc(a,x)  sech(a)^2*diff(a,x);end: `diff/coth` := proc(a,x) -csch(a)^2*diff(a,x);end:

Table 3   Code to modify the differentiation rules for tangent, cotangent, and their hyperbolic counterparts

Table 4 shows that the code in Table 3 really does change the differentiation rules for tangent, cotangent, and their hyperbolic counterparts.

 Table 4   Verification that the code in Table 3 changes the differentiation rules in Maple

Gem 3

Not so long ago I was asked by a user how one could mark points "parametrically." By this, the user meant how can the points  on a parametric curve be marked for specified . This needed no help from a programmer - the desired functionality is built into the PlotPositionVector command in the VectorCalculus packages. Figure 1 shows a simple example of the usage. A curve is defined parametrically with the PositionVector command, and graphed with the PlotPositionVector command.

Figure 1   Use of the PlotPositionVector command to mark points "parametrically"

The alternative is tedious, since the location of the parametrically defined points must be computed, the points defined and graphed separately, and then added to a graph of the curve.

Gem 4

A user recently asked how the graph of  in Figure 2 could be improved, since the range of  is , but the graph doesn't touch the plane . Even with the option grid=[100,100], the graph still isn't satisfactory.

Figure 2   Naive graph of

Our in-house graphics expert made two suggestions, the results of which are shown in Figures 3 and 4.

Figure 3   Improvement 1

Figure 4   Improvement 2

Gem 5

Elementary trig provides the half-angle identity

Unfortunately, Maple does not have a really good implementation of either of the half-angle identities. In fact, the  command

does not list any form of the standard half-angle identities, whereas the command

includes, as the last item in its list, the square of the half-angle identity for the sine function. Thus, Maple does not easily convert expressions such as  to radical form. In particular, when , for example, one needs a definite sprinkling of Maple magic to obtain radicals.  Table 5 shows two different versions of this magic, applied to the fourth-quadrant case .

 = = Table 5   Two methods for converting  to radicals

If  is in the fourth-quadrant, then  is in the second-quadrant where the sine function is negative. Hence, in the first method, the appropriate transformation rule must be known beforehand. In the second method, the assumptions on  and  allow Maple to apply the appropriate form of the half-angle identity unaided.

Legal Notice: © Maplesoft, a division of Waterloo Maple Inc. 2010. Maplesoft and Maple are trademarks of Waterloo Maple Inc. This application may contain errors and Maplesoft is not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact Maplesoft for permission if you wish to use this application in for-profit activities.