# 1

Introduction to Maple

Autumn 2010

Mathematics, University of Exeter

2

Contents
1 Using MAPLE 1.1 What is MAPLE? . . . . . . . . . . . . . 1.2 What can MAPLE do? . . . . . . . . . . 1.3 How do I access MAPLE from Windows? 1.4 How do I get MAPLE to work? . . . . . 1.5 Inserting comments in Maple . . . . . . 1.6 Execution groups . . . . . . . . . . . . . 1.7 On line help . . . . . . . . . . . . . . . . 1.8 Saving your Work on Disk . . . . . . . . 1.9 Restarting MAPLE . . . . . . . . . . . . 2 Examples of Uses of MAPLE 2.1 Recalling Previous Answers . . . . . 2.2 Integer Arithmetic . . . . . . . . . . 2.3 Floating Point Arithmetic . . . . . . 2.4 Unevaluated Expressions . . . . . . . 2.5 Complex Numbers and Arithmetic . 2.6 Polynomials . . . . . . . . . . . . . . 2.7 Labels . . . . . . . . . . . . . . . . . 2.8 Elementary Functions . . . . . . . . . 2.9 Rational Functions . . . . . . . . . . 2.10 Plotting Graphs . . . . . . . . . . . . 2.11 Solving Equations . . . . . . . . . . . 2.12 Finding Complex Roots of Equations 3 Basic Calculus 3.1 Functions in Maple . . . . . . . . . . 3.2 Deﬁnition of a Function . . . . . . . 3.3 Functions of More than One Variable 3.4 Diﬀerentiation of a Function . . . . . 3.5 Composite Functions . . . . . . . . . 4 Further use of Maple 4.1 Diﬀerential Equations . 4.2 Limits . . . . . . . . . 4.3 Taylor Series . . . . . . 4.4 Vectors and Matrices . 4.5 Sums and Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 4 4 5 6 6 6 7 7 7 7 8 9 9 9 11 11 13 14 14 15 17 18 19 19 20 20 21 22 22 23 23 24 25

3 5 Expression Sequences, Lists and Sets 5.1 Expression Sequences . . . . . . . . . 5.2 Lists . . . . . . . . . . . . . . . . . . 5.3 Sets . . . . . . . . . . . . . . . . . . 5.4 Conversion from lists to sets . . . . . 26 26 27 27 29 30 30 31 32 32 34 36

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

6 The Student Package 6.1 Integration by Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Integration by Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Elementary programming in MAPLE 7.1 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A FAQ and Common Mistakes

P.Ashwin@exeter.ac.uk September 16, 2010

• It can calculate with up to thousands of digits using exact or ﬂoating point arithmetic. In this module you will study some of the basic elements of Maple. • It can diﬀerentiate. Thanks! 1. MAPLE is one of the most powerful of these systems and it will be used in several of your courses throughout the next three or four years. • It can plot graphs in 2 and 3 dimensions. NB If you ﬁnd any errors or have any comments on this booklet. integrate and solve diﬀerential equations.2 What can MAPLE do? The following list gives a few of the many features of the MAPLE system. logarithms and many so called special functions which you will encounter later in your degree course. trigonometric functions.3 How do I access MAPLE from Windows? (i) Click on Start in the bottom left hand corner of the screen. • It can manipulate formulae involving polynomials. 1. .uk. • It can solve systems of equations. (ii) Move the cursor to the arrow next to Programs and you will ﬁnd that a menu appears.ac. You will ﬁnd that all of the other Mathematics courses will use Maple throughout the year.1 Using MAPLE What is MAPLE? It is well known that computers can perform numerical calculations very quickly but over the last few years it has also become possible to use computers to perform algebraic calculations using symbols as well as numbers.ashwin@ex.4 1 1. • It can manipulate matrices and vectors with symbolic or numeric entries. please email them to me at p. This course will not only teach you something about Maple but it will also serve as a means of revising some of the Mathematics which you have seen at A-level.

. Move your cursor on to this and double click the left button of the mouse and wait while the MAPLE software is loaded. the plus. for example > 3 + 4. 7 2 If MAPLE says that the statement you have typed is has an error. when you see > anything. The line tells you where the text will appear when you start typing.4 How do I get MAPLE to work? Note you can use MAPLE either in ‘worksheet’ mode or in ‘document’ mode. Now that we have the MAPLE worksheet in front of us we want to get it to do something. We assume here that you use the former. 4 This means that you type in the two. You now have a worksheet in front of you and can begin to type in your commands. you can use the cursor to go back to that statement.5 (iii) Move the cursor to Programming. The result will be given by MAPLE in the centre of the next line. You will notice that whenever the system is waiting for instructions it prompts you with a > sign and a thin vertical line. The semi-colon tells MAPLE when you have ﬁnished typing. Maths and Stats Programmes and you will ﬁnd Maple. You can put more than one calculation on one line. note that you can get a worksheet from File− >New− >Worksheet mode. MAPLE will do nothing until it sees the semi-colon followed by ‘Return’. edit it and press return again to re-execute it. Here is an example. Use the ‘arrow keys’ or mouse to move around within the expression or within the worksheet. ending each one with an ‘Return’. 1.’) and then press ‘Return’ and wait for MAPLE to give the result. In these notes. You can spread your expression over as many lines as you wish. To begin with your most common mistake will be to forget the semi-colon. the second two and the semi-colon (‘. this means that anything is the MAPLE command you type in. > 2+2. 4 − 2.

1 Recalling Previous Answers Maple uses the symbol percent. you do not need to type everything in again. / for division and ˆ for exponentiation.8 Saving your Work on Disk When you have ﬁnished your session on MAPLE you may wish to save it in order to use it on another occasion. you move the cursor to the start of the worksheet and execute each line by typing ‘Return’ on each line. Round brackets are used to indicate precedence. MAPLE will remember the deﬁnitions and results you have generated. It uses ∗ for multiplication.e. This will not remove any text that you have typed in.7 with them to get a better idea of how they work. If you want to copy something similar to a previous expression use the cut and paste facility under the Edit menu. i. 1.e.9 Restarting MAPLE As you execute MAPLE statements in a worksheet. 2 Examples of Uses of MAPLE MAPLE uses + and − for addition and subtraction. Hence . but all statements will not be executed until. 4(2+3) is not the same thing and actually evaluates to 4 so be careful. Double percent i. %% refers to the answer before that and %%% refers to the one before that. as a means of referring to the previous result. Whenever multiplication is implied you must put the * operator. for example. To do this either on permanent disc space or on your pen drive. if you wish that MAPLE forgets all deﬁnitions and starts with its memory empty. % which is obtained by using Shift and 2. Be prepared to use this method a lot in your early experiences of MAPLE! 1. Hence 4*(2+3) will evaluate to 20. see the appendices at the end of this booklet. If you make a mistake with your typing. You can click the mouse so that the cursor is where you want to add or delete the text and just alter the text. type > restart. 2. You cannot go back further than that.

Some of the keywords which will be useful in this area are > igcd(4.12). 36 > %% − %%%.12). 36 > %. 24 which gives the least common multiple > ifactor(36). there is virtually no limit to the number of digits that can be used. If n is a speciﬁc integer then some other useful keywords are ithprime(n) which returns the nth prime number. Unlike a calculator. 5 >6^2. > 100!. 4 which gives the greatest common divisor > ilcm(8.2 Integer Arithmetic The symbol ! is used for factorial. will produce the exact answer.8 > 2 + 3. You can test whether a number is prime by using isprime(n) which tests to see whether n is prime and returns an answer true or false. (2)2 (3)2 will factorise an integer into its prime factors. . 31 2. nextprime(n) which gives the smallest prime number greater than n and prevprime(n) which gives the largest prime less than n.

14 − 8I Complex numbers can be set up as follows.3 Floating Point Arithmetic Pi stands for π = 3.14159.. the basis of complex numbers. z1 := 1 + I >z2:=3+4*I. > z1:=1+I. You can perform complex operations in MAPLE in just the same way as for real arithmetic. evalf(x) stands for ’evaluate x in ﬂoating point’ evalf(x. An example is > (3+2*I)*(2-4*I).. This is vital and you will see it used again later.4 Unevaluated Expressions If you perform a calculation which has an exact answer. To change this type >Digits:=18. The default is that the system works to 10 signiﬁcant ﬁgures..9 2... exp(1) stands for e = 2. 2..718. z2 := 3 + 4I . Now all ﬂoating point operations are evaluated to 18 signiﬁcant ﬁgures. For example > Pi^2+exp(1). As before don’t forget to use the * for all multiplications. MAPLE will not evaluate it unless you speciﬁcally ask for it... These are two of the most used constants throughout mathematics. Note that there is a colon before the equals sign.5 Complex Numbers and Arithmetic In MAPLE the letter I is a reserved character and stands for sqrt(-1).. π 2 + exp(1) 2.n) evaluates x to n signiﬁcant ﬁgures.

abs(cplex). π) 3 convert(z. which gives the real part of cplex > Re(z2).polar). which gives the magnitude or modulus of cplex >abs(z2).polar). converts z into its polar form > convert(z1. which gives the argument of cplex > argument(z1). product and quotient can be obtained by use of the standard mathematical operators. The most important commands in Maple for use in conjunction with complex numbers are Re(cplex). gives the complex conjugate of cplex > conjugate(2-3*I). 3 Im(cplex). π) 4 evalc(cplex). diﬀerence.10 The sum. 2 + 3I polar(r. is a complex number with r as magnitude and t as argument > z3:=polar(2. 5 conjugate(cplex). In the remainder of this section.Pi/3).t). which gives the imaginary part of cplex > Im(z1*z2). 1 z3 := polar(2. attempts to ﬁnd the real and imaginary parts of cplex . 7 argument(cplex). 1 polar( (2). cplex represents a general complex number. 1 π 4 4 arctan( ) 3 > argument(z2).

x2 + 3x + 2 Manipulations can be performed on this such as factorising by using the keyword factor. Hence > evalc(sin(1+I)).732050808I sin(1 + I). MAPLE is perfectly happy to manipulate symbols. 1. + 1. possibly outside the range allowed by the % notation in the previous section. . > x^2+3*x+2.6 Polynomials So far everything we have seen has involved a calculation with numbers.11 > z4:=evalc(z3). x2 + 3x + 2 2. z4 := 1 + I (3) evalf can be used to produce ﬂoating point answers > evalf(z4). will evaluate this. will not be expanded unless you ask for it to be. sin(1) cosh(1) + I cos(1) sinh(1) > evalf(%). 2. In order to do this we use the := symbol to attach a label to an expression. (x + 2)(x + 1) and the reverse process uses the keyword expand > expand(%). > factor(%).7 Labels It is often useful to be able to refer back to expressions. In complex arithmetic use evalc in order to perform complex evaluations.

not a true function (it is sometimes called an apparent function) because the parameter x is ﬁxed. Thus > f:=x^2+3*x. using subs. x := 1 > f. as we did above with Digits (which is a system variable). as we saw above. 4 In order to unassign a name if you wish to use it again as a variable we use > x:=’x’. This is. however. x(x + 3) The labelled expression > f:=x^2+3*x. and whenever this variable is referred to in an expression the value is used. we have to assign a value to x or to do a substitution.12 > f:=x^2+3*x. f := x2 + 3x > g:=factor(f). x := 1 With the deﬁnition of g as above this would produce > g. x is now again the variable x and > g. That is. 4 . > x:=1. f := x2 + 3x looks as though f has been deﬁned as a function of z. g := x(x + 3) > expand(g). f := x2 + 3x > x:=1. f(y) or f(2) is not allowed. x2 + 3x A value can also be assigned to a variable.

f (y). If you now ask for f(2) or f(y) then Maple does not know what to do with the argument and you get > f(x):=x^2+3*x. f (x) := x2 + 3x > f(x). f := x2 + 3x deﬁnes an expression and NOT a function. √ sqrt(x) stands for x exp(x) represents ex log(x) and ln(x) both represent log to base e log10(x) is the log to base 10 Many other functions are also available but those shown above will be the ones which you will see most of during your ﬁrst year. but remember for now that > f:=x^2+3*x. 4 The obvious way of deﬁning functions. Inverse trigonometric functions are also available. You can use the other trigonometric functions in a similar way. f := x2 + 3x > subs(x=1. Similar restrictions will 2 2 apply to the other inverse functions. .f(y). MAPLE uses many of the trigonometric identities when dealing with this type of function.f(2). with x in radians. gives the result 3x.8 Elementary Functions MAPLE recognises all of the standard trigonometric functions. sin(x) will give the value of the sine of x. π ]. 3x. For example arcsin(x) and arctan(x) will return the angle in radians within the range [− π . does not work because when Maple sees say f(x):= 3*x. f (2) We will discuss about ways of deﬁning functions in the next sections. in the special case when the argument is x.13 or > f:=x^2+3*x. Maple stores in a table the information that f. 2. f(x):=.f).

9 Rational Functions These can be deﬁned as follows > g:=(x-1)/((x+1)*(x-2)). just click on a command line on the worksheet. 2. a box appears round it. 2 sin(x) cos(x) + 4 cos(x)3 − 3 cos x cos(x)(2 sin(x) + 4 cos(x)2 − 3) (x + y) (x − y)2 > normal((x^2-y^2)/(x-y)^3).10 Plotting Graphs Another very useful aspect of MAPLE is its ability to plot graphs.x). normal and factor. The graph appears drawn on the worksheet. > f:=sin(2*x)+cos(3*x). > factor(%).x=-2.e. g := (x − 1) (x + 1)(x − 2) A very useful keyword which will express this in partial fraction form is convert > convert(g. use plot: > plot({y. say.e. In order to obtain a graph of. The keyword for producing a graph is plot.parfrac. y = x2 between x = −2 and x = 3 you must type > plot(x^2. Examples are given. You can ﬁnd the coordinates of any point on the graph by moving the cursor to the point and click the left mouse button. f := sin(2x) + cos(3x) > simplify(f). 2 1 1 1 + 3x+1 3x−2 2. To close i.14 Three of the MAPLE keywords which are useful in conjunction with functions are simplify.3).1).. investigate the functions of the row of buttons on the screen immediately above the workspace. remove the box. . For multiple plots i.y^2..y=-1. If you click on the graph. With your graph boxed. several functions on the same graph.y^3}.

use plot3d: > plot3d(x^3*sin(3*y).2..x=0. > solve({x-2*y=7.4). Colour. 2. The equation can be solved by using the keyword fsolve which is the ﬂoating point solve > fsolve(x=cos(x).7390851332 Examples of using ‘solve’ Symbolic solving > solve(f=m*a. To plot 3 dimensional pictures.3*x-y=6}. −1. and investigate how these menus work. . and then again investigate the functions of the row of buttons on the screen immediately above the workspace.{x. eq := x4 − 5x2 + 6x = 2. Then try clicking on Style. > solve(x^2+3*x+2=0). {y = −3. . produces nothing but the prompt for the next input. This is because there is no exact solution. 2.11 Solving Equations The keyword solve enables one or more equations to be solved. 0.2*Pi.y}).15 The graphs should appear each in a diﬀerent colour. −2 If you want to solve a system of equations the the following example shows the method.x).y=0. If you plot a graph of x and cos(x) on the same graph you will see a root between 0 and 1. Axes and Projection above that. f m Equation solving > eq:=x^4-5*x^2+6*x=2.. x = 1} > solve(x=cos(x)).2). The range can also be speciﬁed as > plot(tan(x) x 2*Pi .a). Box this plot by clicking on it.

4 5 Other examples.x)]. −1 + > subs( x=sols[3]. index = 4). 4 5 Assign solutions > assign(sols). > u.16 > solve(eq. √ √ 3.u-2*v-w=0. −1 + > sols:=[solve(eq. RootOf ( Z 5 − 3 Z 4 + 2 Z 2 − Z + 3. RootOf ( Z 5 − 3 Z 4 + 2 Z 2 − Z + 3. 3 = 3. 3 ∗ u + v = 3. u = . u − 2 ∗ v − w = 0 > sols:=solve(eqns).x). 1 = 1. 1.x). 1. index = 2). −1 − √ 3]. v = 2 3 √ 3. RootOf ( Z 5 − 3 Z 4 + 2 Z 2 − Z + 3. 0 = 0 Pick of one component of solution > subs(sols.3*u+v=3. −1 − 3 √ 3 check solutions: > subs(sols. sols := [1. eqns := u + v + w = 1. 1. index = 3). −1 + > sols[3]. 2=2 Systems of equations > eqns:=u+v+w=1. 3 1 w = −1. u). index = 5) . RootOf ( Z 5 − 3 Z 4 + 2 Z 2 − Z + 3.eqns).eq). index = 1). > solve(x^5-3*x^4+2*x^2-x+3. RootOf ( Z 5 − 3 Z 4 + 2 Z 2 − Z + 3.

−1. 1. 0.I .127479307. x = 1. > f:=x^4+4*x^3-8*x^2+32*x-5. x = 1. − − I 3 2 2 2 2 If the roots need to be found numerically by using fsolve then you will need to tell Maple that you are looking for complex roots.1622776602. 0. y = 0. y = 0. x = 0. + 2.x.8565945569I. y = 0.1622776602 Clearly only the two real roots have been found.I. . x<>0).x-y=1). y = −1. y = 0. 1. it will produce the results in the form of a complex number using the standard Maple notation a + Ib > solve(x^2+x+1=0. x = 1.162277660. x = 0 > solve( x^2*y^2=0.03687403922 + . 1 1 √ 1 1 √ − + I 3. f := x4 + 4x3 − 8x2 + 32x − 5 > fsolve(f=0.327862375. x = 1 2.12 Finding Complex Roots of Equations If you use solve to solve a polynomial equation then if the roots are complex.x-y=1. 1. −6.17 > evalf(%). y = −1.x).03687403922 − .162277660. .complex).725868853. 2. − 2. If you also require the complex roots then you must use > fsolve(f=0. −6.8565945569I > solve( x^2*y^2=0.x).

xex − ex In each case the second argument tells the system which variable you are diﬀerentiating or integrating with respect to. > evalf(%).x=1.3). 1 3 x2 dx 26 3 > value(%).. 0 1 ecos(x) dx You can now use the evalf command to obtain a numerical approximation. To set up an integral.x=0.x). use Int.x).. 1 4 x 4 Note the following: > Int(x^2.x). If you need to evaluate a deﬁnite integral then use > int(x^2. > diff(x^2+log(x).x=0. 1 3 1 x If you give it an integral which it ﬁnds diﬃculty in evaluating. . then it will merely display the integral. x3 dx To evaluate it > value(%).1). but not actually integrate it. > Int(x^3. 2x + > int(x*exp(x)..1). > int(exp(cos(x)).18 3 Basic Calculus The keywords diﬀ and int are used for diﬀerentiation and integration respectively.

. not a function. 3. 8 Even redeﬁning the parameter which was used in the deﬁnition does not aﬀect the deﬁnition of the function.1 Functions in Maple We have to be careful when talking about a function in Maple.x=1. > t:=3. 64 . f := x2 + 2x + 3 this is known in Maple as an expression. t := 3 > g(4).2 Deﬁnition of a Function The way in which a function is set up is by deﬁning an operator.19 but > Int(x^2. > f:=x->x^2. The dummy parameter x used in the deﬁnition could be anything and you will see that if we write > g:=t->t^3. When we have used a statement like > f:=x^2+2*x+3.3): > evalf(%). g := t− > t3 > g(2).666666667 3. The symbol -> which is made up of a minus and a greater than sign can be read as ‘maps to’. It is used as follows to deﬁne the function x2 . f := x− > x2 This is read as ‘f becomes x maps to x squared’. 8.

Examples are: > f:=unapply(x^2.x).v). y) = x2 − y 2 the Maple command is > f:=(x. if we use > D(f)(x). since it is evaluated at x. f := (x− > x)2 > f(3). g := x− > 2x However. y)− > x2 − y 2 3. . > f(u. g := x− > x3 + 2x + 4 3.y)->x^2-y^2. For example to deﬁne f (x. y := x3 + 2x + 4 > g:=unapply(y. u2 − v 2 f := (x.4 Diﬀerentiation of a Function We have seen already that we use the command diﬀ(y. In order to diﬀerentiate a function we use the operator D > f:=x->x^2.x). 9 > y:=x^3+2*x+4.3 Functions of More than One Variable The same method can be used to deﬁne functions of more than one variable. 2x this produces an expression.20 An alternative way of deﬁning an operator is to use the unapply command.x) to diﬀerentiate the expression y with respect to x. f := x− > x2 > g:=D(f).

(x.y)->x^4-y^4. (x. namely x. Hence > D[1\$4.2\$3](f). y)− > x4 − y 4 then D[1](f) produces the function based on the derivative of f with respect to the ﬁrst variable. y)− > −12y 2 > D[2\$4](f). D[1. (x + 3)2 > (g@f)(u). sin(3) (z) This looks to be a strange notation and we can see exactly what it stands for if we expand it by using . > D[2.5 Composite Functions If we have two functions deﬁned as f (x) and g(x) then the composition f (g(x)) is written in Maple as (f @g)(x) > f:=x->x^2.21 If we deﬁne > f:=(x.2](f). g := x− > x + 3 > (f@g)(x).2](f) produces the function based on the derivative with respect to x followed by y. (x. will produce a function based on diﬀerentiating the function f. u2 + 3 If the function fcn is repeated n times this can be abreviated to fcn @@ n > (sin@@3)(z). f := x− > x2 > g:=x->x+3. y)− > −24 3. 4 times with repect to x followed by 3 times with respect to y. The \$ symbol can be used as in diﬀerentiation of an expression to signify diﬀerentiation several times with respect to that variable.

1 Further use of Maple Diﬀerential Equations In MAPLE y(x) means a function y which depends on x. If you need to solve dy = xy dx then this would be written as >de1:=diff(y(x).y(x)). When solving a diﬀerential equation you will be trying to determine what function satisﬁes a speciﬁc diﬀerential equation. 1 2 . If f is deﬁned as > f:=x->x^4.22 > expand(%). can also be repeated in the same way. D. sin(sin(sin(z))) The diﬀerentiation operator for functions. f := x− > x4 then the second derivative of the function f evaluated at x is given by > (D@@2)(f)(x). With the above deﬁnition of f this gives 12x2 4 4. y(x) = e 2 x C1 where C1 is an arbitrary constant. de1 := ∂ y(x) = xy(x) ∂x In order to solve it you use the keyword dsolve > dsolve(de1.x)=x*y(x).

An example is > limit(sin(x)/x. sin x and cos x. The most well used are those for ex . where expr is the expression whose value is required as x tends to a. 4 25 Left and right limits can also be found: > limit(l/x^2. left). x=0. Again you will spend much more time on this topic in other courses. right). You will study the theory of Taylor series in more detail in your other courses. x=0. x=0). The general form is > limit(expr.x=a). ∞ 4.x=0).3 Taylor Series The command taylor calculates a truncated Taylor series. This is usually used when an expression is of the form 0/0 or ∞/∞. undeﬁned > limit(1/x. This is a well known limit which will produce the answer 1 The limit of an expression as x tends to inﬁnity can also be found: > limit((4*x^2 + 3*x +7)/(25*x^2 + 9).23 4. x=0). −∞ > limit(1/x. ∞ but > limit(l/x. x=infinity). However you may have seen some simple examples of Taylor series already.2 Limits Another very useful tool in Maple is the limit command. The . The command gives you the limiting value of an expression as the variable tends to a speciﬁc value.

It is often useful to get rid of the order term from a taylor command because you will ﬁnd that you cannot plot such an expression. All you have to do is to type in > with(linalg). 4. > v:=vector([1.n). The default in the system is for the order to be 6.24 Taylor series is a power series and it will always be displayed in Maple up to a certain order which tells you which is the next term in the series which is not explicitly evaluated.4 Vectors and Matrices All of the keywords used in this section are contained in a separate package in MAPLE and this must be loaded before you can use it. This new expression may now be plotted. and this produces 1 1 1 5 1 x + O(x6 ) 1 + x + x2 + x3 + x4 + 2 6 24 120 The general form of the taylor command is > taylor(expr. This will produce a 3-dimensional vector. or > evalm(v).3. This converts it to a polynomial by getting rid of the order term. A Maclaurin series is a Taylor series about x = 0.polynom).x=a. We will see what this means with an example. . where % refers to the Taylor expansion on the previous line. The command is very simple. The most important keywords in this section are vector and matrix which set up exactly what they say. The exponential series can be looked at by using > taylor(exp(x). you will not be given all of the entries of v but merely the name v itself. If you wish to see the entries in v on the screen you must type > print(v).x). This can be done by using > convert(%. where you want the Taylor series for expr about x = a up to terms of order xn . Examples of each are given.7]). If you just type > v.

b) will produce the scalar and vector products respectively of these vectors.. Again an example will show how this is done. This sets up a matrix with 2 rows and 3 columns with elements 1 3 5 in the ﬁrst row and 0 3 1 in the second row. Other operations include the elementary row and column operations and reduction to row echelon form rref(). where expr is an expression and a and b are integers.infinity). In this case you need to specify 3 facts.0. the number of columns and the entries row by row of the matrix.3. inverse and transpose will perform those operations on a matrix by using > inverse(A).3.i=a.5 Sums and Products Maple is able to calculate ﬁnite sums and products and is sometimes able to work out inﬁnite ones. The command to produce a product of two matrices is > evalm(A &* B).e.i=1.n=0.1])..b) and crossprod(a. However. use A &* B and not A&*B. The general form of the sum command is > sum(expr.[1. More details are given in the Vector and Matrices module. for multiplication you must use &* and this operator must always have spaces around it.b). A few examples are > sum(i^2..25 If a and b are deﬁned as 2 vectors then the keywords dotprod(a. 4. In a similar way matrices may be deﬁned. There are many other operations that can be used after typing with(linalg). For addition and subtraction use the normal + and −. exp(1) If Maple cannot ﬁnd a closed form for a sum then it is returned unevaluated and just as with integrals you can use evalf to obtain a numerical answer.3. 385 > sum(1/n!. > transpose(A). i. These are the number of rows. Calculations involving matrices can be performed using evalm which means evaluate matrix. > A:=matrix(2. for example det can be used to ﬁnd the determinant of a matrix.5.10). It is . The general form for products is very similar.

5. > 1. −2 .1 Expression Sequences The simplest of these is the expression sequence.26 > product(expr. −2 >sol:=%.b.i=a. −1. sol := −1.5).3. 3 > x. −2 Expression sequences may be concatenated > f.sol.x). a. c > solve(x^2+3*x+2=0. y > x. 2.y. x. f := a. 120 5 Expression Sequences. b.3^4. For example when solving a quadratic equation we obtain two solutions.b). Lists and Sets Quite often it is necessary to deal with more than one expression at once.c.. b. Maple has a variety of ways of bundling expressions together.2. −1. 1. This is entered simply by writing each of the expressions separated by a comma. (x + y)2 .n=1. c. An example of this is >product(n.. > f:=a. 81 Expression sequences may be assigned to variables.(x+y)^2. x.

[−2.27 The null sequence is generated by the keyword NULL and nothing is shown on the screen as shown below. 3. 7] When using sort on a list of names Maple sorts them into alphabetical order. 0. green.7]. 3] The main diﬀerence between expression sequences is seen when they are concatenated.y. 1. red] The empty list is denoted by [ ] 5. 3. x := 5. x := {1.3}. [blue.3].0. > x:=NULL. b] The separation is still maintained unlike in the case of the expression sequence. A := [1. 3].b].2. y := [a.2.-2. 2. > x:=[1.3. 7] > sort(A). b] > x. > y:=[a. > x:={1. [a. > A:=[1. 3} . −2. 0.2 Lists A list is an expression sequence written in square brackets. [1. x := [1. 2. > sort([red. 2.blue]). A numerical list can be sorted by using the sort command.3 Sets A set is an expression sequence written in curly brackets.green.

2} There are three operations deﬁned on sets. 2.0. {1. 5} > a intersect b.3.2}. A[2] its second and so on. Sets are not ordered and they may not contain duplicates.1}. 4.2.5}.x.1}. 5} > a union b. 2.-sin(z). {4. 3. 2. > a:={5. − sin(z) .3}.2.2. {1. 2} > b minus a. > {0. a list or a set we use a selection operation. b := −1. 5} > a[3]. x. 4 > b:=-1. > a:={1.4. a := {0.4. 3} > b:={3. > {1.28 Sets are more complicated than lists in that there are some automatic simpliﬁcation rules. namely union.2. a := {1. {3} > a minus b. 2. intersect and minus which work in the same way as the mathematical deﬁnitions. 3} {0. Extraction is only possible when the list or set or sequence has been assigned to a variable. 1. b := {3. {1. 4. If A is a variable containing a list or set or expression sequence then A[1] returns its ﬁrst operand. 5} The empty set is denoted by { } To extract part of an expression sequence. 4.

set) which converts the list a into a set. 2.1-z. 3. 1 − z} Conversion in the opposite direction is done using a special case of the selection operator. 3. With the above deﬁnitions of a and b we have > op(2. y. x.x. op can pick out speciﬁc elements and nops gives the number of elements.list) converts the set b into a list. The keywords op and nops are useful when using lists and sets. x. {1. then all elements are selected. 1 − z] > {a}. z So lists can be converted to sets or sets to lists using expression sequences as a half-way house. 1 − z > [a].2. x.4 Conversion from lists to sets The conversion from expression sequence to a list or set is simple as follows.3. 2. z} >a[].4]. convert(b. 4] > b:={x.z}. y. An alternative to this is to use the Maple command convert which is of the form convert(a. x 5. [1. b := {x.29 > b[2]. a := 1. a := [1. 4 > b{}.y. > a:=1. 1. If you specify no selection range. x. > a:=[1. y .b).

giving I3 = cos vdv At this stage you should know the answer to this integral and so all you need to do is to type . The ﬁrst argument is the change you want. It enables you to work through a problem step by step rather than just being given the answer and it may help give you a better understanding of the techniques of integration. the second is the integral to which it is to be applied and the third is the variable you want in the new integral. 4 6 The Student Package This package enables the use of several integration methods.x). It is called by using > with(student). I1 := 4x3 cos(x4 + 2)dx One of the key methods for integration is by substitution. In this case this should produce I2 := cos(u + 2)du A second change of variable would be > I3:=changevar(v=u+2. This can be done in Maple by using > I2:=changevar(u=x^4. Make sure you don’t use int otherwise the answer will be displayed immediately and this will take all the fun out of it! > I1:=Int(4*x^3*cos(x^4+2). 6. which loads the package.30 > nops(a).v).I1.u). In this case we want to make a change of variable u = x4 .I2. We shall use it solely for looking at analytical evaluation of integrals.1 Integration by Substitution First set up the integral you require by using Int. both analytical and numerical.

x).x). and the Maple command to be used is intparts which operates as follows > intparts(I1. The integral is set up in the same way as before. is the ﬁrst operation to perform.u=x^4. The correct method would be to write > intparts(I1. > I1:=Int(x*sin(x). which will produce sin v Finally you will back substitute to produce > subs(v=u+2. 6.sin(x)). to give sin(x4 + 2) This technique can be applied in just the same way to deﬁnite integrals.%). The ﬁrst argument is the integral and the second is the part of the integral which is to be diﬀerentiated. This is because we have chosen the wrong part to diﬀerentiate. −x cos(x) − This can be simpliﬁed using > value(%).2 Integration by Parts This is again a part of the Student package and so > with(student). −x cos(x) + sin(x) − cos(x)dx . In the above case this would produce 1 sin(x)x2 − 2 1 cos(x)x2 dx 2 This is clearly more complicated than the original integral.31 > value(%).

One integral which will often occur throughout your work is of the form ex cos(x)dx This needs two integrations by parts. branches. etc. 7 Elementary programming in MAPLE Internally. od: > for x from 1 to 3 do > print(x): 1 2 3 > for x from 5 to 1 by -2 do > print(x): 5 3 1 > od. This can be done using Maple by repeating the command intparts. Maple consists of a rather small number of commands for the formation of loops. procedures. > od. which should give the answer. solve) are written in this programming language.I2). 7. ..g.32 Some integrals need repeated application of integration by parts. If the original integral is deﬁned as I2 then once we have used parts twice the answer can be determined by using > isolate(I2=expand(%). These commands make up the programming language of Maple. by which time the original integral reappears.1 Loops Loops can be formulated using for or while with do . We can use these commands to write our own programs. All other commands (e...

. > od. a1 := 3 sin(πr) > od.33 > for i in [1. > od. a2 etc.k0. automatically > for j from 1 to 4 do > a||j:=(2*j+1)*sin(j*Pi*r).19] do > print(i): 1 5 19 > x:=0: > while (x < 3 ) do > x:=eval(x)+1: x := 1 x := 2 x := 3 Hence a program to sum the ﬁrst 10 odd integers could look like the following: > total:=0. total := 0 > for i from 1 to 19 by 2 do > total:=total+i: > od: > print(total).9).. 100 A useful facility is the concatenation operator ‘||’ which can be used for example to generate the variable names aO.5. al. 100 As we saw previously. we could also have done this using the sum keyword > sum(2*k+1.

we could have added them up in the loop where we generated them..34 a2 := 5 sin(πr) a3 := 7 sin(πr) a4 := 9 sin(πr) If we subsequently wanted to add these all up...1 > evalf(total2). else ... 41. elif condition2 then .. else and ﬁ. case distinctions and conditions can be formulated in Maple using the keywords if.. elif . 7.. The syntax is: if condition1 then ..1 then > r:= 0.2 Branches Branches....) If we wanted to evaluate total2 at say r = 0. total2 := 3 sin(πr) total2 := 3 sin(πr) + 5 sin(πr) total2 := 3 sin(πr) + 5 sin(πr) + 7 sin(πr) total2 := 3 sin(πr) + 5 sin(πr) + 7 sin(πr) + 9 sin(πr) (Of course.45233957 > od. total2 := 0 > for j from 1 to 4 do > total2:=total2+a||j.. .1. .. r := . then > total2:=0. then. elif condition3 then .

For example: > x:=0: > do > > > x:= eval(x) +1: if x<>3 then break. fi.35 ﬁ. print (x): 1 2 > od: .

• You have forgotten to put a ‘. Restart Maple. It seems to produce the wrong answer in a calculation. . • You are too impatient. for example 2^1/2 is diﬀerent from 2^(1/2) • You have not deﬁned a function correctly (see section 3.1). eg 4(2 + 5) instead of 4 ∗ (2 + 5). wait a bit longer! • You have ﬁlled up the memory with rubbish (eg by calculating π to 106 digits). • You have omitted the * in an expression. check that you have executed the line by pressing ‘Return’ when the cursor is on that line.. eg you cannot use matrix until you have typed with(linalg). Nothing happens when I press ‘Return’ at the end of a line I’ve typed in or it doesn’t recognise commands I’ve typed in. • Certain quantities that are deﬁned in the worksheet seem not to be deﬁned. • You have omitted some brackets. • If a plot does not appear. are you trying to plot complex numbers on real axes? • You are trying to use a command that has not been loaded.’ or a ‘:’ at the end of a line.36 A FAQ and Common Mistakes It takes ages for the MAPLE to calcuate something.