You are on page 1of 26

>

Welcome to Maple 8
"Command the Brilliance of a Thousand Mathematicians."
[sic] Care of Adam Bowers, just one mediocre mind. >

Basic Commands
All Maple commands must end with either a semicolon ( ; ) or a colon ( : ). The difference between the two is that the colon suppresses output. > a:=5; a := 5 > b:=-6: When assigning values to a name, you must use a := Otherwise, no assignment is made. > c=13; c = 13 You can view what is assigned to a name at any time. > a; 5 > b; -6 > c; c The basic algebraic operators are what you might expect: +, -, *, and /. > a+b; a-b; a*b; a/b; -1 11 -30 -5 6 You need not assign values to a name to work with it. > a*c+z;

5c+z If you want to use a new value for a name, just go ahead and assign something new: > a:=14570; a := 14570 > a;b;c; 14570 -6 c You can also unassign names, so they have no specified value: > unassign('a'); > a; a > > b:=evaln(b); b := b That command assigns the name of a name, not the value > b; b > You can also assign functional values. > f:=x^2-1; f := x - 1 > g:=x+1; g := x + 1 > h:=1/x; h := > f+g; x +x Try the factor command. > factor(f+g); x (x + 1) Maple is case sensitive.
2 2

1 x

Mobius := A name in Maple need not be only one letter. x -1 > F/f. x +x F := x > F.1) If an expression can be simplified. > So what if I want to know what a function is at a certain domain value? How do we find. > f. x x -1 > simplify(F/f). use the command simplify to do so. h := > Mobius:=(a*z+b)/(c*z+d). x -1 2 2 2 2 2 2 2 + 1 x -1 2 sin(x y) x az+b cz+d . x +x x (x .> F:=(f+g)*h. say. x+1 > expand(F/f). > simplify(F). f(3)? Well. 1 x-1 Now let's try something more complicated. we just substitute the value 3 in place of x. > > h:=sin(x*y)/x. x +x x > f.

b d > subs(z=1-I. what was that "I" thing? You probably can guess that I = let's talk about some . > > -1 .. > subs(x=3. (1 . 2 Special Commands and Characters > > Want some Pi? > The command for pi=3. > > subs(z=0. we have to tell Maple very explicitly what to do.. 8 Here we substituted x=3 into the function f.f). that's not going to work. > ? evalf > > . 3.> f(3)..Mobius).I) c + d Oh wait . That brings up a good point.I) a + b (1 . x(3) .Mobius).141592654 Wait a minute? What command was that? If you don't know a command. you open the help documentation by typing a question mark and then the command. is > Pi. π > evalf(Pi).1 Well....1415.

> unassign('x'). 2I x~ The ~ that appears after the x is Maple's way of letting us know it's assuming something about x. x+yI So how do you do square roots. 2 -x Why didn't it pull out the I? Maybe x<0. Maple can't distinguish. anyway? > sqrt(-1). not a lower case "i". > w:=5-I*3. there is no ~ after the x. but remember that -1 = I > Use a capitol "I" for an imaginary number. Let's make it forget that assumption. unless we tell it in advance. > assume(x>0). x Good.> Complex numbers are nIce. I > sqrt(-4*x). > Maple can also tell us the real and imaginary parts of a complex number. -3 . so Maple doesn't think it's positive anymore. > sqrt(-4*x).3 I > Re(w). > I^2. -1 > x+I*y. 5 > Im(w). > x. w := 5 .

We can also check to see if those assumptions actually worked using the is command. > is(a.real. true > is(b.real).real).assume(c.c.b. 3 13 > Let's get back to our Mobius function.Mobius)).real). 2 2 2 2 -a + a I . > additionally(b. because we never made that assumption.assume(d. -2 13 > Im((3-4*1)/(2+3*I)).real. > Mobius. false Maple said b was not an integer. > assume(a.c.real).integer). æ -a + a I .b -c + c I .real). -b~ c~ + a~ d~ 2 c~ + 2 c~ d~ + d~ Actually we could have made those assumptions at the same time: > assume(a. Mo1 := > Re(Mo1).d.assume(b. > Re(Mo1).d ø Maple cannot tell if a.integer).> Re((3-4*1)/(2+3*I)).d are real or imaginary. so it cannot give us the real part.real.d .real).b ö Âç ÷ è -c + c I .b. 2 a~ c~ + a~ d~ + b~ c~ + b~ d~ 2 c~ + 2 c~ d~ + d~ > Im(Mo1). az+b cz+d > Mo1:=simplify(subs(z=1-I.

-1 > sin(Pi/4). > a:='a'.> is(b. false > > Trigonometry is a Pythagorean's best friend > The three main trig functions are: > sin(x). d:='d'.real). c:='c'. sin(x) > cos(x). I'll remove all of my assumptions by assigning names to a.integer).c.b. true For more assumption commands. and d. a := a b := b c := c d := d > is(a. false > is(b. 0 > cos(Pi). 2 2 . just type them in: > sin(0). type ? assume > ? assume Just to be safe. b:='b'. cos(x) > tan(x).integer). tan (x) To evaluate on numbers.

Error. Error. > sin(x)*csc(x). arccos(cos(x)) > arccos(cos(Pi)). it'll let me know.` unexpected Oops. 5 > arcsin(sin(5)). > simplify((sin(x)/cos(x))*cot(x)). I forgot to close up my parentheses. `.> tan(Pi/2). so I'll use % which will input whatever was last output. Although the error message might be unintelligible. 1 > The inverse functions just have "arc" written in front of them: > sin(arcsin(5)). > simplify(%). (in tan) numeric exception: division by zero Oops. I just tried to divide by zero. π > . Let's simplify. cos(x) > simplify((sin(x)/cos(x)*cot(x)). 5-2π > cos(arccos(x)). Whenever I try to do something Maple can't do. sin(x) csc(x) Oops. x > arccos(cos(x)). let me try that again. too. > And all of our other favorites are here. that didn't work. 1 > simplify(1/sec(x)). but I don't want to type the whole thing again.

0 > exp(ln(2)). sin(x) + cos(x) > simplify(%). sin(x + y) For more information on how to use trig commands. e > exp(Pi*I)+1. e > exp(-1). > (sin(x))^2+(cos(x)^2). not in the middle. too. 2 The command ln is the natural log command. tf := sin(x + y) > expand(tf). too.Maple is pretty good with trig identities.trig). but you can use log. > exp(x). > exp(log(2)). you have to use the exp command. just type > ? trig > > 2 2 It's very natural Using exp and log > If you want to find an exponential. 1 Note that the ^2 was after the sin(x) and cos(x). sin(x) cos(y) + cos(x) sin(y) > combine(%. > > tf:=sin(x+y). 2 (-1) x .

solve(x^2-4.{x.solve(x^2-1=3. > solve({x^2-1=3}. Maple chose it to be x.y}). {x = -2} If you want to solve for 0. z = ý 2 2 þ î In this system. > solve({x^2-4. y = 3} > solve({x+y+z. ì 5x 3 xü . 2.x-2}. simply use the solve command.{x}).y=í x=ý 5 5 þ î Of course. -2 To put the solutions into a set. {x = 2}. ì 2z 3 zü .x). -2 You can also solve a system of equations for several unknowns. {x = 2} > solve({x+3*y-1.y.x). you can just leave it out of the list of unknowns. -2 2.{x}). > solve(x^2-1=3. not all systems of equations have a solution. In the above family of solutions.x).3*x-2*y}. y-3}.> > > > > Solving Equations To solve equations for unknowns. as well as the unknowns.x).z}).3*x-2*y}. one of the unknowns is a free parameter. . > solve({x+y+z. put the equations or unknowns in a set.y= í x = x.{x.y}). {x = -2} {x = 2}. if you would rather have the unknowns in terms of z. {x = -8.{x. but be sure to put all of the equations into a set. 2. you don't need the equals sign: > solve(x^2-4=0. You can see that y and z are solved in terms of x.

.[-sin(x).2.[3. There are several ways to define a matrix: > M:=matrix([[-2.x-4}. In this case.{x}).6]). > > A:=matrix(2. é -2 ê ê 7 ë -4 11 -6ù ú 15ú û 2 5 3ù ú 6ú û 0ù ú 1ú û Okay.2..3. so what happened there? The command evalm tells Maple I am about to evaluate something with matrices.sin(x)].3. I do &* so Maple knows a matrix is being multiplied by another matrix and not a scalar. and whenever that operation is matrix multiplication.4. > evalm(M &* N). é cos(x) sin(x) ù B := ê ú ê -sin(x) cos(x)ú ë û > C:=evalm(3*A-B). to signal that there was no solution.cos(x)]]).> solve({x-1. é 1 A := ê ê 1 ë That's a 2x2 matrix with all entries 1. é -2 M := ê ê 3 ë > N:=matrix(2.1]]). > B:=matrix([[cos(x). I was given no output. > > > Matrix Manipulation One of the things I use Maple for most often is to solve linear algebra problems.[1.1). é 1 N := ê ê 4 ë I wonder what the product of those matrices are.5.0]. 1ù ú 1ú û .

é 3 C := ê ê 4 ë 2ù ú 3ú û 1ù ú 0ú û æ πö ù sinç ÷ ú è 2ø ú ú ú æ πö ú cosç ÷ ú è 2ø û So now I have a matrix.2]. 4 I put the name of the matrix. 3.cos(x)ú û I have just decided I am only interested in the case x=Pi/2.é 3 . I can get it all by itself using the following command: > C[2.2].2]. > BB:=map2(subs. é 0 ê ê -1 ë > C:=simplify(evalm(3*A-BB)). Let's say I really like looking at entries in the 2nd row 1st column. 1st index. > C[1. so I didn't have a entry for C[3.sin(x) ù ú 3 . Error. so I need to use the map2 command.1].B).cos(x) C := ê ê 3 + sin(x) ë 3 . é æ πö ê cosç ÷ ê è 2ø BB := ê ê ê -sinæ π ö ç ÷ ê è 2ø ë > simplify(BB).x=Pi/2. This command will map the command subs into each matrix entry. so why don't I substitute in the value? I have to remember that Maple has a hard time knowing matrix commands from scalar commands. larger than upper array bound 2 There is no third row in my matrix C. 2 > C[1. followed by a list containing the row and column numbers: MatrixName[RowNumber. > .ColumnNumber].2]. 6006 > C[3.1]+999*C[1.2]. 0 > 1002*C[2.1]-C[2.

ratform. é 3 ê ê 4 ë 2ù ú 3ú û The op command. intbasis. C > op(C). pivot. eigenvals . innerprod. multiply. addcol. rank.) > Now we can take an inverse. smith. extend. you can just ignore any warnings of "redefined and unprotected". potential. blockmatrix. indexfunc. jacobian. > with(linalg). rowspace. eigenvects . coldim. é 3 Ctrans := ê ê 2 ë > evalm(C &* Cinv). If you choose not to suppress the output with a colon. among other things. gausselim. exponential. colspace. normalize. (For now. dotprod. randvector . colspan. singularvals . vecpotent. htranspose. adj. bezout. iszero. jordan. GramSchmidt. entermatrix. definite. companion. concat. basis. permanent. laplacian. shows the matrix instead of just the name. stackmatrix. addrow. band. curl. rowdim. vector . fibonacci. frobenius. matrix. trace. 1 > Cinv:=inverse(C). charmat. charpoly. ffgausselim. grad. linsolve. minor. scalarmul. sumbasis. toeplitz. det. diverge. angle. randmatrix. in this case the linalg package. wronskian] The command with tells Maple to open up one of the predefined packages. hilbert. nullspace. delcols. > det(C). norm. JordanBlock. matadd. forwardsub. delrows. geneqns. crossprod. swapcol. or find a transpose. Warning. kernel. é 3 Cinv := ê ê -4 ë > Ctrans:=transpose(C). hermite. mulrow. subvector . rref. leastsqrs. cholesky. mulcol. eigenvalues . swaprow. 4ù ú 3ú û -2ù ú 3ú û . called linalg. QRdecomp. the protected names norm and trace have been redefined and unprotected [BlockDiagonal. augment. diag. hadamard. genmatrix. cond. inverse. LUdecomp. vectdim . > C. sylvester . ismith. gaussjord. it lists all commands in the package. adjoint. hessian. row. issimilar.If I want to do anything more interesting. backsub. eigenvectors . minpoly. equal. submatrix. copyinto. vandermonde. I'll have to use the PACKAGE made for linear algebra. rowspan. ihermite. orthog. col. Wronskian. transpose.

é a ê A := ê 0 ê ê ë 0 > X:=diag(x.y. you can find which matrix will get you from one to another.c).b.z).é 1 ê ê 0 ë > A:=diag(a. > phil:=randmatrix(3. é ax ê ê 0 ê ê ë 0 0 by 0 0ù ú 1ú û 0 b 0 0ù ú 0ú ú ú cû 0 y 0 0ù ú 0ú ú ú zû 0ù ú 0ú ú ú c zû You can do some nifty things with linalg. é 63 ê george := ê 45 ê ê ë 92 57 -8 43 -59ù ú -93ú ú ú -62û -55 97 56 -37ù ú 50ú ú ú 49û (randmatrix gives a random matrix of specified dimensions. .george).) > martha:=linsolve(phil. é x ê X := ê 0 ê ê ë 0 > evalm(A &* X).3). é -85 ê phil := ê -35 ê ê ë 79 > george:=randmatrix(3. using the linsolve command. For example.3).

2 b + 8 d. > evalm(phil &* martha . > evalm(phil &* martha). é 63 ê ê 45 ê ê ë 92 57 -8 43 -59ù ú -93ú ú ú -62û If you didn't trust your matrix reading ability.MN[2. eqs := {2 a + 8 c.8].4 c ë Let's list the entries in a set: > eqs:={MN[1. é 0 ê ê 0 ê ê ë 0 Now let's try something involving unknown quantities. é a N := ê ê c ë I want M &* N to be the zero matrix.MN[2.d]]). é 2 M := ê ê -1 ë > N:=matrix([[a.-4]]).2]}.[-1. -a .4 d} Now we solve. > MN:=evalm(M &* N).[c. > M:=matrix([[2.1].4 d ú û bù ú dú û 8ù ú -4ú û 0 0 0 0ù ú 0ú ú ú 0û .4 c.b].MN[1. then you could check by subtraction. -b .1].george).é ê ê ê ê martha := ê ê ê ê ê ê ë -228262 121529 -811145 121529 1523214 121529 -142414 121529 -571276 121529 989141 121529 225184 ù ú 121529 ú ú 562519 ú ú 121529 ú ú ú -1159702 ú 121529 ú û So martha should take us from phil to george. é 2a+8c MN := ê ê -a .2]. 2 b + 8 dù ú -b .

.. a = -4 c} So any matrix of the form a=-4c and b=-4d will suffice.. but you'll have to enter a domain. For more information. d = d.sols. empty plot . otherwise Maple might get confused.5).x=-5. but remember to use the map2 command..> sols:=solve(eqs. sols := {c = c. the function y=1/x). use the plot command.. Be sure to separate the endpoints of the domain with two periods (as in ".c. é -4 c newN := ê ê c ë -4 dù ú d ú û This is just the tip of the linalg iceberg.{a. > plot(1/x). > plot(1/x.")..N). just type ?linalg > > > > > Plots in 2 and 3 Dimensions If you want to graph a function (for example. Plotting error. We can substitute these values into out matrix.b.d}). . b = -4 d. > newN:=map2(subs.

y=-5..5.. > plot(1/x.500 400 300 200 100 0 -4 -2 0 2 x -100 4 -200 Ouch! That's not very useful.x=-5..5). Try specifying a range .. .

that's much better. Let's try something in three dimensions. . but now we have to use plot3d.4 y 2 0 -4 -2 0 2 x 4 -2 -4 Yeah.. > plot3d(sin(x*y)/(x*y).x=-2..2).2.y=-2.

export as an eps file. If you right click.If you want. just type ?plots > ? plots > > > > > . The plots command inequal will allow you graph sets of inequalities. and many other things. you can change colors. For more info. you can move it around by clicking on it and dragging your pointer around. you should try the plots package. For more advanced plotting.

e > diff(diff(g. remembering to tell Maple which variable with which to differentiate.x). 6 And that was a third derivative. 3x +4x-4 If we want a second derivative. 0 Two more examples. g := sin(x) + tan (x) + e > diff(g.x). > diff(diff(f. 2 sin(x) cos(x) + 1 + tan (x) > diff(g. > diff(sin(x*y)/x.4 x + 1 > diff(f. e > diff(diff(g. Just use the diff command on your function.x).Segregation is Bad. but Differentiation is Good.x).x).y). Let's differentiate the function > f:=x^3+2*x^2-4*x+1.y). f := x + 2 x .x). > g:=(sin(x))^2+tan(x)+exp(y). cos(x y) > diff(log(x)/x. just nest the diff commands. y 2 2 2 y 2 2 y 2 3 2 . Let's do something a bit more interesting. Differentiation is quite straightforward.y). 6x+4 > diff(%.y).x).x).2 sin(x) + 2 tan (x) (1 + tan (x) ) > diff(diff(g.y).x). 2 cos(x) .

x).. but you can tell Maple to overlook that problem. > diff(int(f. > int(1/x.x=-10.x).Pi).1 x > > > > 2 - ln(x) x 2 Integration Integration is done much like differentiation. > int(f.10.x). f := x + x + x + 1 > int(f.10)."). undefined > int(1/x.x).x=0. x +x +x+1 > int(diff(f.x=0.2). -I π 3 2 3 2 3 2 > > . You can also do definite integrals (don't forget the ".. but the command is int.x).x=-10. 2 A function might be discontinuous. 1 4 1 3 1 2 x + x + x +x 4 3 2 the diff and int commands can work together. 32 3 > int(sin(x). > f:=x^3+x^2+x+1....'continuous'). x +x +x Notice that there is no constant of integration.

P1 := r cos(θ) > P2:=int(P1. P2 := > P3:=int(P2. > > 2 2 r 2 π γ 1 . so Maple might give you something like this: > h:=exp(-x^2)*log(x).x=0. > > lantern:=1..phi=0. some things can still be done. h := e > int(h.ln(2) 4 2 π (-x 2) ln(x) If-Then.theta=0. you could do it all in one go: > int(int(int(r*cos(theta)*sin(phi).Pi/2)..Pi/4).Pi/4).Pi/2).r=0.2)... . One more example: > P:=r*cos(theta)*sin(phi).x)..2). and other ways to get confused. P3 := Of course.Some functions might be hard to integrate. lantern := 1 > if lantern=1 then print(`By land`) fi.r=0.. 2 For more.infinity). ó 2 ô e (-x ) ln(x) dx ô ô õ But don't give up. just type ?int at the prompt. > int(h..phi=0.theta=0. P := r cos(θ) sin(φ ) > P1:=int(P. For-Do.

you can use the else command. lantern := 2 > if lantern=1 then print(`By land`) else print(`By sea`). (Note that any text in the print command must be inside `single quotes`. In the previous example. > > if a>=b then print(`greater than or equal to`) else print(`less than`). How . a := 3 b := 4 > if a<b then print(`less than`) fi. less than In this example. you must have an opposing fi. By sea This might not be exactly what you want.) > > a:=3.b:=4. not 'single quotes'. In cases where this might happen. the syntax is if [condition] then [result] fi. because any value for lantern other than 1 will give `By sea`. By land > lantern:=2. fi. > if a>=b then print(`greater than or equal to`) fi. fi.By land When writing an if-then command. but that's okay. > > if lantern=1 then print(`By land`) else print(`By sea`). I used more than one line. fi. less than But the condition might not be satisfied. I used shift-enter to make a blank line below the prompt. as long as I remember to put semi-colons (or colons) in all but the first line. For every if.

fi. 1 2 3 When writing a for-do command. you must have a opposing od. There are no other choices! > Usually. of course. if-than commands are not used on there own. > for i from 1 to 3 do i^5 od. like a for-do command. Usually. TWO if by sea. There are no other choices!`). > for i from 1 to 3 do print(i) od. > The for-do commands make it much easier to do repeated calculations. > lantern:=3. -2997200869907 29991 -2998100399969 29994 -999666703331 9999 We can put if-then commands inside of for-do loops.do we solve this problem? By making our program longer. . For every do. 1 32 243 > for k from 9997 to 9999 do 1/k+k/3-k^2 od. the syntax is for [index] from [starting value] to [finishing value] do [expression] od. TWO if by sea. they are used inside of other structures. I said ONE if by land. fi. lantern := 3 > if lantern=1 then print(`By land`) else if lantern=2 then print(`By sea`) else print(`I said ONE if by land.

even) then print(`even`) else print(`odd`) fi. od.`Are you smoking on the job. .0]]).-1.`By sea`) fi. > for lantern from 1 to 3 do if lantern=1 then print(lantern. if lantern>2 then print(lantern. By land 2. x1 := 1 x2 := 2 x3 := 3 x4 := 4 x5 := 5 x6 := 6 > for m to 6 do if is(x||m. 1.`By land`) fi.3]. od.1. odd even odd even odd even > for number from 4 to 6 do y||(number-3):=x||number. if lantern=2 then print(lantern. y1 := 4 y2 := 5 y3 := 6 Now something a bit trickier.[-1. By sea 3. lantern := lantern Now I have made sure that the name "lantern" has no value assigned to it. > M1:=matrix([[0.3]. Henry?`) fi. Henry? A few simple examples: > for j to 6 do x||j:=j od.[0. Are you smoking on the job.> lantern:='lantern'.1. od.

3.-4.`huh?`) fi od.[2. Usually they are planted in programs.é 0 ê M1 := ê -1 ê ê ë 0 1 -1 1 3ù ú 3ú ú ú 0û > M2:=matrix([[2. do it .1].[3.-2]. 2 é 2 ê M2 := ê 0 -4 ê ê 1 ë 2 > M3:=matrix([[1..[0. 1 é 1 ê M3 := ê 2 2 ê ê 3 ë 3 > for i to 3 do linalg[det](M||i)..1.2.4].2]. od..j]=Pi then print(M3[i.Pi]]). huh? > For loops can get really complicated. od.1.. π. but that is a topic for another time..4]]).2. > > . For more information just type ?for > ?for Go on .[2.j].. -3 -40 0 -2ù ú 4ú ú ú 4û 1ù ú 2ú ú ú πû > for i to 3 do for j to 3 do if M3[i. you know you want to .