A Brief Introduction to Maple – Basic Manipulations and Plots

demo-maple.mws

Douglas B. Meade (meade@math.sc.edu)

1 What is Computer Algebra?

Much of your mathematical background has probably be focused on developing the ability to solve equations and analyze functions. The sophisticated manipulation of symbols and expressions that you use to solve equations and investigate functions can also be performed by a computer algebra system (CAS). A CAS can be use to generate many of the exact symbolic solutions typically obtained by hand, the numerical approximations found using a calculator, and the graphs sketched by hand. A CAS is a software package that works directly with an expression as a basic data structure (compare this to most software packages that require numeric data and perform numeric operations on the data).

Maple is one of several CASs; other major examples are Mathematica, Macsyma, Derive, and MathCad. The ability to work directly with mathematical expressions means that floating point errors arise only when floating point operations are explicitly requested.

2 Documentation and On-Line Help

The on-line help for Maple is very good – once you learn how to use it. The help pages describe the syntax of each command, briefly describe the algorithm used to implement the command, and provide a few examples illustrating the use of the command. The examples can be very helpful. I will often cut and paste an example from a help page into my worksheet, confirm that the example works as advertised, then modify the arguments to answer my question.

To obtain help on the command func, type ?func or help func at a Maple prompt (which, typically, is >).

Note that any text in this worksheet that is red and in the Times font is Maple input. Hyperlinks are dark cyan (green) and underlined; clicking on this text will transfer

Of course, this works only if the name of the function, or a reasonable keyword associated with the name, is known. The Topic Search and Full Text Search (located under the Help menu on the title bar) provide efficient access to the contents of the help library. The Quick Reference page provided together with this supplement are also quite helpful.

It is a good idea to begin EVERY worksheet with the restart command. This ensures that all of Maple’s memory is cleared. Future operations can be performed without risk that previous definitions will interfere with the processing (see ?restart for the on-line information about this command):

> restart;

3 Essential Facts

Maple is a computer language; it cannot read your mind. Maple does follow your instructions to the letter. This means that you need to learn to communicate your needs to Maple in a way that it understands.

Some basic symbols and other fundamentals:

• assignments are made with := (plain = has a different meaning)

– this gives the value of the right hand side (RHS) to the name on the LHS

• every command is separated by a semi-colon ( ; ) or colon ( : )

– with the latter the computation is done, but the result is not displayed

• the double quotes ( ” ) refers to the result of the immediately preceding computation

• Maple is case sensitive

– that is, the names x and X are different, pi, Pi, and PI are not the same thing

• sets are delimited with { }; lists are delimited with [ ]

– members of a set are unordered; order is preserved and meaningful in a list

• intervals (aka ranges) are specified using .. ( as in a .. b)

– this is how Maple indicates the interval [a, b], that is, the real numbers from a to b

• ? or help – commands for accessing information from the on-line help archives • mathematical functions are denoted by their standard names:

+ (addition)

- (subtraction)

* (multiplication) / (division) ˆ (exponentiation) sin, cos, tan abs, sqrt exp, log, ln

• Common constants are predefined in Maple, their names are: Pi, I, and infinity

– note that E is no longer defined in Release 4; references to Euler’s constant should be replaced with exp(1) and Eˆ x should be entered as exp(x)

• names are assumed to be complex valued except for a few special situations (see ?evalc) or when explicitly specified otherwise (with assume)

4 Basic Arithmetic Calculations

In the following lines, use paper and pencil to first predict what you think Maple will do. Then execute the command and see what actually happens! Note any unexpected results. Can you explain Maple’s response (or lack thereof) in each case?

> number := 4 * 6 + 12 / 6 - 1 ;

number := 25

> power := (-3)^3 ;

power := −27

> abs( " );

27

> Pi ;

π

> v:= sin( Pi / 4 ) :
> w:= v^2 ;

w := \frac{1}{2}

> v ;

\frac{1}{2} \sqrt{2}

> tan( -Pi / 2 ) ;
Error, (in tan) singularity encountered
> 3 / ( 5 - sqrt( number ) ) ;
Error, division by zero

Now enter some commands of your own! To produce the input prompt either select Insert Execution Group (After Cursor) from the Insert menu or, equivalently, click on the icon that looks most like the Maple prompt (the eleventh icon from the left) or simply press CTRL-j. Any of these will produce a new input region below the current cursor position. Be generous with the space bar to make your commands easy to read, and to edit (modify after the fact). Also, go back to the tangent calculation above and change it to compute the tangent of \frac{π}{3} .

Now for some slightly more impressive computations

> 2^100;

1267650600228229401496703205376

> evalf( Pi, 250 );

3.1415926535897932384626433832795028841971693993751058209749445923\ 07816406286208998628034825342117067982148086513282306647093844609\ 55058223172535940812848111745028410270193852110555964462294895493\ 0381964428810975665933446128475648233786783165271201909

> 400!;

64034522846623895262347970319503005850702583026002959458684445942\ 80239716918683143627847864746326467629435057503585681084829816288\ 35174352289619886468029979373416541508381624264619423523070462443\ 25015114448670890662773914918117331955996440709549671345290477020\ 32243491121079759328079510154537266725162787789000934976376571032\ 63503315339653498683868313393520243737881577867915063118587026182\ 70169819740062983025308591298346162272304558339520759611505302236\ 08681043329725519485267443223243866994842240423259980555161063594\ 23769613992319171340638589965379701478272066063202173794720103213\ 56624613809077942304597360699567595836096158715129913822286578579\ 54936161765448045322200782581840084843641559122945427538480355837\ 45180226759000613995601455952061272111929181050324910080000000000\ 00000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000

5 Simple Expressions and Functions

Now let’s define a few functions and see how Maple operates with these. (The only difference is that in these examples the name x does not have a value.)

> f := sin( 2 * x ) ;

f := sin(2 x)

> g := 4 * x^2 ;

g := 4 x^{2}

> h := 0.25 * cos ( 8 * x ) ;

h := .25 cos(8 x)

> p := f * g ;

p := 4 sin(2 x) x^{2}

> u1 := f * h ;

u1 := .25 sin(2 x) cos(8 x)

> u2 := f + h ;

u2 := sin(2 x) + .25 cos(8 x)

5.1 Technicality regarding functions and expresesions

Technically, each of these is an expression.

A function can be defined using the arrow operator (->), proc, or unapply. Note specifically, that we have not typed any command in the form: f(x) := sin(2*x);.

6 Plotting

Graphs of functions are produced by the plot command (see ?plot). In its simplest form, plot needs to know the function to be plotted and the range of values for the independent variable. Note that a..b is Maple’s way of describing the interval [a, b]. Observe that I have placed signed titles on some of these graphs. When you actually print plots to turn in with an assignment, they MUST have a title and signature [by your initials or last name]. Again, try to predict the output before tapping the return key!

   > plot( 3 * t - 2 , t = -3 ..  10, title=`My First Maple Plot`
   ) ;

   > plot( f , x = -Pi ..  2 * Pi ) ;

   > plot( p , x = -6 ..  8 , title = ` f * g [by DM] ` );

These plots are nice, but what information do they convey? Let’s concentrate on the plot of f g, that is, of p. Position the cursor on a point on the graph and click the left button. The numbers that appear in the left-most box on the third line of Maple’s header are the coordinates of the current location of the cursor. Use this technique to identify the global maximum and minimum values of f g on the interval [−6, 8], and the x-values at which these are found. Where do other (local) minima and maxima occur? Can you guess the exact values?

   > plot( 2 * u^3 + 4 * u - 5 , u = -10 ..  7 ,
   > title = ` cubic function [by DM] ` ) ;

Where does the cubic function cross the u-axis? Maybe it would be helpful to cut down the plotting interval from [−10, 7] to [−1, 3], or even narrower, say to [0, 1.5]. Try it. Can you find the u-intercept to 2-decimal point accuracy by this process? It is a powerful method, which we call ZOOMING IN.

> plot( u1 , x = -1.2 ..  1.2 );

> plot( u2 , x = 0 ..  3*Pi ) ;

Can you explain why the graphs of u1 and u2 look the way they do? To plot more than one function on the same set of axes, just specify the

functions to be plotted as a list or set. (What advantage is there to using a list rather than a set?)

> plot( [ p , g , -g ] , x= -6 ..  8 );

Can you identify the three different plots? What about the next one? Can you explain the little bumps that appear inside the large dips in the graph of u2?

> plot( { f , h , u2 }, x=0 ..  3*Pi );

6.1 Plotting Discontinuous Functions

The tangent function is well-known to all of us.

   > f := tan(x);

f := tan(x)

Note: This definition completely replaces the previous definition of f.

Recall that the graph of y = tan(x) has vertical asymptotes at all odd multiples of \frac{π}{2} . Let’s see how Maple handles this. (Recall that we have already seen that Maple knows that the tangent function is undefined at odd multiples of \frac{π}{2} .)

   > plot( f , x = -Pi ..  Pi, title=`First Attempt` );

• Is this what you expected to see?

• Why does the graph look like this?

• What can be done to improve the appearance of the plot?

There are two problems. First, we have to tell Maple that this function is discontinuous. But, there is more. Look at the labels on the vertical axis. The units are (on most platforms) in BILLIONS; we want to see the details on a much finer scale. Let’s limit the vertical scale to the range from -10 to 10. Each of these pieces of information is an optional argument to plot (see ?plot,options for the description of all optional arguments).

> plot( f, x = -Pi ..  Pi , -10 ..  10 , discont=true );

This technique is very useful for any function that has asymptotes.

OK. Now it’s your turn. Add appropriate optional arguments to the following command to produce a graph from which you can identify the local minimum and local maximum. (Don’t forget the title.)

> plot ( ( 10 - 4*t^3) / ( 1 - t^2 ) , t = -3 ..  5 );

6.1.1 Point to Ponder

Now, one last challenge. Use your graph to estimate the (oblique) asymptote for this function. Check your estimate by graphing the function and the asymptote in the same plot.

These examples only scratch the surface of Maple’s abilities when it comes to plotting. Maple can also produce 3-D plots (see ?plot3d), plots of parametric curves and surfaces, animated sequences (see ?animate or ?display or ?animate3d or ?display3d). The best general source of information is the on-line help for the plots package.

7 Calculus Manipulations

Consider the following sequence of operations relating to the function x(t) = e^{(−α t)} cos(ω t + θ). What information is obtained in each step?

   > restart;
   > x := exp(-alpha*t)*cos(omega*t+theta);

x := e^{(−α t)} cos(ω t + θ)

7.1 Derivatives

   > dx := diff( x, t );

dx := −α e^{(−α t)} cos(ω t + θ) − e^{(−α t)} sin(ω t + θ) ω

> dx2 := diff( x, t$2 );

dx2 := α^{2} e^{(−α t)} cos(ω t + θ) + 2 α e^{(−α t)} sin(ω t + θ) ω − e^{(−α t)} cos(ω t + θ) ω^{2}

> factor( dx );

−e^{(−α t)} (α cos(ω t + θ) + sin(ω t + θ) ω)

> CP := solve( dx=0, t );

CP := −\frac{θ + arctan(\frac{α}{ω})}{ω}

> subs( t=CP, dx2 );

α^{2} e^{(\frac{α (θ+arctan( \frac{α}{ω}))}{ω})} cos(−arctan(\frac{α}{ω})) + 2 α e^{(\frac{α (θ+arctan( \frac{α}{ω}))}{ω})} sin(−arctan(\frac{α}{ω})) ω

− e^{(\frac{α (θ+arctan( \frac{α}{ω}))}{ω})} cos(−arctan(\frac{α}{ω})) ω^{2}

> dx := simplify( " );

dx := −\frac{e^{(\frac{α (θ+arctan( \frac{α}{ω}))}{ω})} (α^{2} + ω^{2})}{\sqrt{\frac{α^{2} + ω^{2}}{ω^{2}}}}

Since the derivative will be negative (for real values of ω, α, and θ), this critical point must be a (local) maximum. The value of the function at this maximum is

> X[max] := simplify( subs( t=CP, x ) );

X_{max} := \frac{e^{(\frac{α (θ+arctan( \frac{α}{ω}))}{ω})}}{\sqrt{\frac{α^{2} + ω^{2}}{ω^{2}}}}

7.1.1 Points to Ponder

• Can the same information be obtained using the Second Derivative Test?

• What is the second derivative of x?

7.2 Integration

Indefinite and definite integration is obtained in a natural way.

> Int( x, t );

∫ e^{(−α t)} cos(ω t + θ) dt

> value( " );

−\frac{α e^{(−α t)} cos(ω t + θ)}{α^{2} + ω^{2}} + \frac{ω e^{(−α t)} sin(ω t + θ)}{α^{2} + ω^{2}}

> simplify( " );

−\frac{e^{(−α t)} (α cos(ω t + θ) − sin(ω t + θ) ω)}{α^{2} + ω^{2}}

Note that the constant of integration is not included in these results. How could you manually include the constant of integration?

Definite integrals are very similar. Here’s an example taken from the CRC Tables of Integrals.

> Int( u/sin(u), u=0..Pi/2 ):
> " = value( " );

∫_{0}^{1/2 π} \frac{u}{sin(u)} du = \frac{1}{8} I π^{2} + 2 Catalan + \frac{1}{4} π ln(2) − \frac{1}{2} π ln(1 + I)

The presence of complex numbers in this result is (at first) surprising. It is not difficult to see that this quantity is real. (Note the use of : and = to improve the appearance of the output.)

> evalc( rhs( " ) );

2 Catalan

Now, what is Catalan? (see ?Catalan) A numerical (approximation to the) value of this integral is

> evalf( " );

1.831931188

This example illustrates a very important feature of Maple. Even though a problem is stated in terms of real quantities, the computational algorithms sometimes require the use of complex analysis. It is also very important to remember that all names are, by default, assumed to be complex valued. Many common calculations actually require an additional assumption on a parameter. This can be very frustrating, but it can also help us to better understand the problem. (It is one of the most common questions that I see on the Maple User’s Group.)

To illustrate, consider the following two improper integrals:

   > int( exp(-u^2), u=0..infinity );

\frac{1}{2} \sqrt{π}

   > int( exp(-a*u^2), u=0..infinity );
   Definite integration: Can't determine if the integral is convergent.
   Need to know the sign of --\TEXTsymbol{>} a
   Will now try indefinite integration and then take limits.

lim_{u→∞} \frac{1}{2} \frac{\sqrt{π} erf(\sqrt{a} u)}{\sqrt{a}}

Note that Maple is unable to evaluate this limit until something is known about the parameter a.

   > assume( a>0 );
   > about( a );
   > int( exp(-a*u^2), u=0..infinity );

\frac{1}{2} \begin{matrix}√ & \overline{π} \\ √ & \overline{a} \end{matrix}˜

7.2.1 Note about tildes (˜ ) in output for assumed names

Note the tilde (˜ ) after the name a. This is Maple’s way of reminding the user that assumptions have been made about a. This default can be changed by using the interface command with the showassumed argument; see ?interface for additional details.

The following assignment is used to reset the name a to its unassigned state.

   > a := 'a';

a := a

   > about( a );

7.3 Limits

Here is a simple limit example.

> L := Limit( tan(theta), theta=Pi/2 );

L := lim_{θ→(1/2 π)} tan(θ)

> value( L );

undefined

> limit( tan(theta), theta=Pi/2, right );

−∞

7.4 Application: Integration of a Rational Function

> restart;

Consider the proper rational function

> f := (x^2-26*x-47)/(x^5+5*x^3+3*x^4+11*x^2-20);

f := \frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20}

The antiderivative of f (which we will call F) can be obtained by a variety of different means. Let’s examine a few and compare the information obtained in each case.

> F := Int( f, x );

F := ∫ \frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20} dx

The simplest, but least instructive, approach is to simply let Maple do all the work.

Note that the constant of integration is not automatically included in indefinite integrals.

> F = value( F ) + C;

∫ \frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20} dx =

−\frac{4}{3} ln(−1 + x) + \frac{1}{3} \frac{1}{x + 2} + \frac{23}{27} ln(x + 2) + \frac{13}{54} ln(x^{2} + 5) + \frac{91}{135} \sqrt{5} arctan(\frac{1}{5} x \sqrt{5}) + C

or, even,

> int( f, x );

−\frac{4}{3} ln(−1 + x) + \frac{1}{3} \frac{1}{x + 2} + \frac{23}{27} ln(x + 2) + \frac{13}{54} ln(x^{2} + 5) + \frac{91}{135} \sqrt{5} arctan(\frac{1}{5} x \sqrt{5})

To emphasize integration techniques while still avoiding algebraic complications, we can utilize Maple to determine the partial fraction expansion of the integrand.

> fpf := convert( f, parfrac, x );

fpf := −\frac{4}{3} \frac{1}{−1 + x} − \frac{1}{3} \frac{1}{(x + 2)^{2}} + \frac{23}{27} \frac{1}{x + 2} + \frac{13}{27} \frac{7 + x}{x^{2} + 5}

From this partial fraction decomposition it is now a relatively simple matter to compute the integral BY HAND. The result can be compared with the previous answer

> int( fpf, x );

−\frac{4}{3} ln(−1 + x) + \frac{1}{3} \frac{1}{x + 2} + \frac{23}{27} ln(x + 2) + \frac{13}{54} ln(x^{2} + 5) + \frac{91}{135} \sqrt{5} arctan(\frac{1}{5} x \sqrt{5})

The third, and final, approach to this problem will be the most detailed. The purpose here is to emphasize the process of finding a partial fraction expansion without fear of unmanageable algebra.

The key here is to enter the correct form for the partial fraction decomposition. This depends upon the irreducible factors in the denominator of f:

> factor( denom( f ) );

(−1 + x) (x^{2} + 5) (x + 2)^{2}

The appropriate general form for the decomposition will be

> FORM := a/(x-1) + b/(x+2) + c/(x+2)^2 + (d+e*x)/(x^2+5);

FORM := \frac{a}{−1 + x} + \frac{b}{x + 2} + \frac{c}{(x + 2)^{2}} + \frac{d + e x}{x^{2} + 5}

The second step is to determine the (linear) equations that define the constants a, b, c, d, and e.

> eqn := f = FORM;

eqn := \frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20} = \frac{a}{−1 + x} + \frac{b}{x + 2} + \frac{c}{(x + 2)^{2}} + \frac{d + e x}{x^{2} + 5}

> simplify( eqn );

\frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20} = (a x^{4} + 4 a x^{3} + 9 a x^{2} + 20 a x + 20 a + b x^{3} + 3 b x^{2}

+ 5 b x − 10 b + b x^{4} − c x^{2} − 5 c + c x^{3} + 5 c x + 3 d x^{2} − 4 d + d x^{3} + 3 e x^{3} − 4 e x + e x^{4}) /((−1 + x) (x^{2} + 5) (x + 2)^{2})

> eqn2 := collect( ", x );

eqn2 := \frac{x^{2} − 26 x − 47}{x^{5} + 5 x^{3} + 3 x^{4} + 11 x^{2} − 20} = ((b + a + e) x^{4} + (3 e + c + 4 a + d + b) x^{3}

+ (3 d + 3 b − c + 9 a) x^{2} + (−4 e + 20 a + 5 c + 5 b) x + 20 a − 4 d − 5 c − 10 b)/((−1 + x) (x^{2} + 5) (x + 2)^{2})

This equation will be satisfied (for all real values of x, except x = 1 and x = −2) for any solution to the following system of five equations with five unknowns.

> eq1 := a+b+e=0;
> eq2 := 4*a+b+c+d+3*e;
> eq3 := 9*a+3*b-c+3*d = 1;
> eq4 := -4*e+5*b+5*c+20*a=-26;
> eq5 := -5*c-10*b-4*d+20*a = -47;

eq1 := b + a + e = 0

eq2 := 3 e + c + 4 a + d + b
eq3 := 3 d + 3 b − c + 9 a = 1
eq4 := −4 e + 20 a + 5 c + 5 b = −26
eq5 := 20 a − 4 d − 5 c − 10 b = −47

The solution to these equations is:

> COEFFS := solve( {eq1,eq2,eq3,eq4,eq5}, {a,b,c,d,e} );

COEFFS := \{c = \frac{−1}{3}, b = \frac{23}{27}, a = \frac{−4}{3}, d = \frac{91}{27}, e = \frac{13}{27}\}

Substituting this result, which is a set, into the original form for the partial fraction decomposition yields

> subs( COEFFS, FORM );

−\frac{4}{3} \frac{1}{−1 + x} − \frac{1}{3} \frac{1}{(x + 2)^{2}} + \frac{23}{27} \frac{1}{x + 2} + \frac{\frac{91}{27} + \frac{13}{27} x}{x^{2} + 5}

Let’s confirm the answer

> simplify( " );

\frac{x^{2} − 26 x − 47}{(−1 + x) (x^{2} + 5) (x + 2)^{2}}

The integral is now much simpler to evaluate by hand, but here it is one last time according to Maple.

> int( "", x );

−\frac{4}{3} ln(−1+x)+\frac{1}{3} \frac{1}{x + 2}+\frac{23}{27} ln(x+2)+\frac{13}{54} ln(27 x^{2}+135)+\frac{91}{135} \sqrt{5} arctan(\frac{1}{5} x \sqrt{5})

Note that this same outline can be used for ANY partial fraction problem. The key steps are i) knowing the correct form for the decomposition and ii) understanding how to identify the conditions that the coefficients must satisfy. These are (relatively) high-level concepts; the user is relieved of the rather complicated mechanic manipulations.

8 Copyright

demo-maple.mws – a Maple worksheet to demonstrate basic functions of Maple Prepared by: Douglas B. Meade (7 March 1996) as part of the Maple Supplement for Nagle/Saff (Addison-Wesley) Updated to Maple V, Release 4, by Douglas B. Meade (27 December, 1996) For more information, please contact the author at one of following addresses: Department of Mathematics, Univ. of South Carolina, Columbia, SC 29208 (803) 777-6183 meade@math.sc.edu (copyright, Douglas B. Meade, 1996)