Mathematics 2270 -01, Spring 2005 (Adapted from N. Korevaar by Oana Veliche) The purpose of this tutorial is to get you going with MAPLE. You can follow this tutorial to introduce yourself to the software MAPLE, and use it to do some basic matrix computations. related to the linear algebra we've been talking about. Depending on your previous experience you may want to skip various sections. 1) X-windows, opening netscape, maple, mail, more: Xwindows are not so different from P.C. windows or Mac windows; on the other hand they have their own idiosyncrasies, so you should experiment to see how to open and close windows, resize them, move them about, and find them if they happen to get hidden. For Math 2270 purposes you need to be able to open Netscape (to download files) and Maple (to work on them). Open Netscape by finding it on one of your mouse buttons, under the choice "browsers", or by moving your cursor into a local window and then typing netscape &, followed by . The & tells X-windows to create a separate process for netscape, keeping your local window free for more UNIX commands. Once netscape opens, go to the Math undergraduate page http://www.math.utah.edu/ugrad/lab.html , and explore computer lab information (Computer Lab). Finally, open a Maple window one of two ways: from the middle or right mouse button (depending on the specific computer you are using) you may choose xmaple, or you can type the command xmaple &, followed by , into a local window. 2) Maple: If you are starting the tutorial at this point (because you're doing it on your own at another location or already knew the Math Lab system), you should have opened a maple window as well as a web browser. Maple is partly just a very fancy calculator; it can do practically any undergraduate mathematics computation or symbolic manipulation. You can write programs in Maple and draw pictures as well. You can intersperse text with computations using the toolbar: to get a computation prompt click on the ``[>'' box near the top. To insert text click on the ``T'' box. Or you can change command fields (starting with "[>") into text fields by putting the cursor into them and then choosing "T". You can use the mouse to cut, paste, and edit a document. You can change fonts, formats, and use other standard text editing tools by choosing appropriate menu items. This document you are reading is a Maple document even though it is largely text. You will learn by doing - and by asking your neighbor or the lab assistant. New User's Tour: Under the Help button at the top right of your Maple window you will find the choice "New User's Tour". This is a good way to learn generally about what Maple can do. After making this menu choice Maple may hide the beginning of the tour behind other active windows; use the "Window" menu item to bring the tour window to the front. If you wish you can explore now, or you can continue with the notes below and come back to the tour later. To close the new tour (or any other top window), use the ``close'' option inside the ``file'' menu item. To keep the tour open but bring another window to the front, use ``window'' menu item. Entering Maple commands: To give you a flavor of what Maple can do, we will try a few commands. Move your cursor into the "Untitled" (new) Maple window which you created. Commands begin on lines having a command prompt ``>'', and should be ended with either a semicolon ; or a colon : If you end with a semicolon you will see visible output, if you end with a colon the output will be suppressed even though the command is executed. Maple will not execute a command until you type the ``return'' or ``enter'' key. If you have a multiline command use ``shift-return'' to change lines without executing. If you incorrectly align parentheses or brackets, or do something else which makes your command unexecutable you will get a ``syntax error'' message and Maple will try to point out your mistake with the cursor and cryptic diagnostic phrases. After a while you will become good at fixing these mistakes but they can be annoying at first. Spaces are ignored in Maple, so you may use them to make input easier to read. You can enter explanatory comments in a command line by inserting a ``#'' to the left of the comments; Maple ignores any text after the #. Sometimes this is more informative then entering nearby explanatory text, especially if you are explaining various steps in a subroutine. Now, let's try some commands. (You try just the math commands, the editorial comments were only added to explain what the particular commands are illustrating ! ) Check that you understand what each command is doing. > 3+4; 4+5: 6 * 7; #one of these computations will not be shown > #even though all three will be done. > 7 42 > (3+4)7; #if you want to multiply you must use *, so after > #trying the command as given, insert a * to fix the > #resulting syntax error. You can execute a line or > #execution group (bracketed on the left) if > #your cursor is anywhere in it. You can move the > #cursor with the mouse or the arrow keys. Maple will > #try to put it in a good place if it detects an error. Error, unexpected number > (3+4)^2/7; 3+4^2/7; evalf(3+4^2/7); #the evalf command gives a decimal > #approximation instead of an algebraic expression. > #Notice that if given a choice, Maple computes powers > #first, then multiplies and divides, and finally > #adds or subtracts. 7 37/7 5.285714286 > diff(x^2,x); #``differentiate x^2 with respect to x'' 2 x > diff(exp(sin(x))*x^3,x); #a harder differentiation problem > #you should get output: 3 2 cos(x) exp(sin(x)) x + 3 exp(sin(x)) x > f:= x-> exp(sin(x))*x^3; > diff(f(x),x); #the same problem done in two steps. > #The first line shows the format for defining > #functions in Maple. (Did you use ``shift-ret''?) 3 f := x -> exp(sin(x)) x 3 2 cos(x) exp(sin(x)) x + 3 exp(sin(x)) x > int(t^2*exp(t),t); #``integrate (t^2)*exp(t) with respect > #to t'' (Maple doesn't put in the integration constant.) 2 t exp(t) - 2 t exp(t) + 2 exp(t) > int(t^3*exp(sin(t)),t); #this shows that Maple is not God: > #If it can't find an elementary-function > #antiderivative it just echos what you put in. > #you should get: / | 3 | t exp(sin(t)) dt | / > evalf(int(t^3*exp(sin(t)),t=0..1)); #But you could do > #a definite integral numerically even if Maple > #can't compute an elementary antiderivative 0.5112814089 > Pi;exp(1);evalf(Pi);evalf(exp(1));infinity; > #some important numbers Pi exp(1) 3.141592654 2.718281828 infinity Entering Text: Scroll to somewhere in your worksheet and add some text with the ``T'' menu item. (If you move your cursor to a command field and the press the [> button with your mouse, Maple makes a new command field directly below it. If you move to the new command field and press the T button you will have a text field into which you may write, using the rudimentary word processing tools on the Maple menu bar. Now scroll to the top of your file and insert the title ``My first Maple worksheet'' (center it with the menu option on the right side of the toolbar), as well as your name and today's date. When you are doing your Maple projects you will be expected to hand in more than a page of computations: You will be expected to add text explanations of what you've been doing. Saving Files: It is always a good idea to save your maple file periodically. Do this now using the tool bar, using the "save" option under the "File" menu item. The first time you save a new file, and any time you use the "save as" option, you will be asked to name your file and say where you want to keep it. You name it in the left part of the box, being careful to keep the suffix ".mws" so that Maple knows this file is a Maple Work Sheet. If your directory is new you probably have not made any subdirectories yet (unix command mkdir, in a local window), but as you create more files you may wish to organize where you save them using the tree structure of Unix directories, which you can follow in the right side of your saving box. Unfortunately our UNIX is not set up so that you can visually see your directory/file tree like in PC windows or Macs. You use various UNIX commands in your local window to organize your directories. It will probably happen some time that you will crash Maple long after your last save. This will not make you feel happy but will teach you an important lesson. Printing: Go to the file menu option and choose the print option. You get a little printer setup box. If you then click on the print command circle, type the command "lpr -Plcb115" followed by ``enter'' or by a click on the print box at the bottom of the window, a paper copy will come out of the printer at the side of the lab in LCB115. (Note that if you use this command from the undergraduate computer lab your file will print in LCB115 and you may not be able to retrieve it. If you are printing in the computer lab in the math center, you will have to enter a different printer name following the -P. Ask an assistant in the lab for the appropriate printer name.) Alternately, you can use the output to file circle to create a postscript file which you can then print anywhere, using the appropriate unix commands. For example, to print a postscript file to the lab printer from a local window, the command would be "lpr -Plcb115 myfile.ps", followed by the return key. You do not put in the quotation marks, but leave spaces exactly as indicated. The lpr stands for line printer, the -P stands for print, and the lcb115 is the name of the printer. Downloading Maple documents: This document is available online in several formats, if you follow the links from the class homepage at http://www.math.utah.edu/~oveliche. Files with suffix ".mws" or ".txt" can be downloaded from your browser and then opened from Maple. To download a file click on the name with your right mouse button and then select "Save Link As". This will open a box that allows you to specify where to put the file and what to name it. If you click "okay" without typing anything, the file will be saved to your home directory using the name specified on the website. The ".mws" suffix means the file is a Maple Worksheet, and should open from Maple to look just like this file. The ".txt" suffix is Maple text, and you should only try it if the ".mws" file doesn't open. It's a cruder form of this file, but potentially more universal. The ".pdf" versions of the file are for reading from your browser (with Acrobat reader), but you can't execute these from Maple. If you click on the ".pdf" versions with your left mouse button, a readable document should open. Go to the course homepage address using your browser, follow the link to the Maple page, and find and save the Maple Tutorial tutorial.mws file to your home directory. Now return to your Maple window and use the ``file'' menu item to open tutorial.mws. It should appear in the central box after you choose "open". Click on it with the mouse to highlight it and then click ``OK'' or type ``return''. A copy of this tutorial should then appear in your Maple window, as a Maple document that you can work in. Notice you can use the "Window" menu item at the top of your Maple window to change between various open files. (Sometimes when you open a new file it goes to the back of your pile. Then use the Window option to bring it back to the front.) If you know the exact URL of a Maple file, and you are in version 6 or 7 of Maple, you can use the "open URL" option under "File" to have Maple do the downloading and opening for you. This saves steps if it works correctly. If you couldn't open the Maple worksheet file, go back to your browser and save the ".txt" version of the tutorial. Then go back to Maple, and follow these directions: In order to open a ``Maple text'' document, which this is, you must chose open from the file menu option. In the resulting open file dialog box go to the filetype box at the bottom, click on the triangle to see the list of choices, and use your mouse to choose ``Maple text.'' At this point ``IntroTutorial.txt" should appear as a choice in the central box. Click on it with the mouse to highlight it and then click ``OK'' or type ``return''. A copy of this tutorial should then appear in your Maple window, as a Maple document that you can work in. The copy is not as pretty as your xerox (the execution groups are all single lines, and the text formatting is not as neat, and some output may be lost), but it is O.K. It has text and it has Maple input. Execution Groups: You can modify the text and input using the toolbar and menu options. You will notice many brackets on the left of the document. These are execution groups. Maple will execute everything in one execution group at once, and then move the cursor to the next execution group. You can create large execution groups by highlighting sections of a document, going to the Edit option and picking join execution groups. You can remove brackets by highlighting them with the mouse and deleting them with the delete key or the menu option. And you already learned how to insert new prompts or new text wherever your cursor is, by using the [> and T buttons on your toolbar. 3) Linear Algebra, and using Maple's help windows: So, it looks like Maple might be interesting to use in Calculus, but how do we find out what it can do for us in that subject, or in another subject, say linear algebra? It is instructive to use the Help directory located at the upper right-hand corner of the maple window. That's what you're going to do now. Can Maple do matrix operations, or even define matrices? Of course! Here's how you would try to find the right commands if you did not know them already, or if I was not going to tell you below: Click on the Help option at the upper right corner of your Maple window. A little window opens with further choices. Pick Topic Search, by highlighting it, and a help window should appear. (If it doesn't, it's hidden behind your worksheet; use the ``window'' option in your menu to bring it to the front.) Try searching for linear algebra. At this point you should get a help window about the linear algebra library. There seem to be a lot of commands. You could try finding the one you wanted from this page, or you could do a more specific search. For example, either look up matrix, or click on it from the linear algebra page. Notice if you go to the bottom of a help window, you can often figure out how the command works without reading all the fine print above. We can use matrices if we load the linear algebra library of procedures: > with(linalg); #to hide the list of commands in this > #package use a colon instead of a semicolon [BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, coldim, colspace, colspan, companion, concat, cond, copyinto, crossprod, curl, definite, delcols, delrows, det, diag, diverge, dotprod, eigenvals, eigenvalues, eigenvectors, eigenvects, entermatrix, equal, exponential, extend, ffgausselim, fibonacci, forwardsub, frobenius, gausselim, gaussjord, geneqns, genmatrix, grad, hadamard, hermite, hessian, hilbert, htranspose, ihermite, indexfunc, innerprod, intbasis, inverse, ismith, issimilar, iszero, jacobian, jordan, kernel, laplacian, leastsqrs, linsolve, matadd, matrix, minor, minpoly, mulcol, mulrow, multiply, norm, normalize, nullspace, orthog, permanent, pivot, potential, randmatrix, randvector, rank, ratform, row, rowdim, rowspace, rowspan, rref, scalarmul, singularvals, smith, stackmatrix, submatrix, subvector, sumbasis, swapcol, swaprow, sylvester, toeplitz, trace, transpose, vandermonde, vecpotent, vectdim, vector, wronskian] And now we copy the commands from the matrix help window: (For long ones we would use our mouse!) > matrix(2,2,[5,4,6,3]); #a 2 by 2 matrix with > #successive entries as indicated [5 4] [ ] [6 3] > matrix([[5,4],[6,3]]); #same matrix [5 4] [ ] [6 3] So that's how to make a matrix. By the way, to close the help files after you've used them use the ``file/close '' sequence in the toolbar, or the equivalent key stroke given next to it, which is simultaneous ``control-F4'' on my work station. Or you can keep them around and return to your worksheet with the ``window'' menu option. 4) Some Linear Algebra computations: Can you figure out the syntax of the commands and their meanings? Some of these commands will be useful later. Use the help windows for more details about them. This simple example could easily be done by hand; larger ones could not. > A:=matrix([[1,1,1],[2,3,2],[3,8,2]]); > #coefficient matrix for a linear system, > #``:='' is used to define the object on > #its left by the construction on its right [1 1 1] [ ] A := [2 3 2] [ ] [3 8 2] > A[2,3]; #one of the entries of A 2 > b:=vector([1,1,-3]); #the right-hand side for > #a linear system Ax=b b := [1, 1, -3] > augAb:=augment(A,b); #the augmented matrix [1 1 1 1] [ ] augAb := [2 3 2 1] [ ] [3 8 2 -3] > C:=rref(augAb); #compute the reduced row echelon form > #of the augmented matrix [1 0 0 1] [ ] C := [0 1 0 -1] [ ] [0 0 1 1] > x:=col(C,4); #read off the solution vector to Ax=b (fourth column of C) x := [1, -1, 1] > evalm(A&*x)=evalm(b); #check your answer > #NOTE A good way to do matrix operations use the evalm > #command. Addition is +, but matrix multiplication > #is &*. (Scalar times matrix is *.) [1, 1, -3] = [1, 1, -3] > x:=linsolve(A,b); #another way to solve linear systems. x := [1, -1, 1] > Ainv:=inverse(A); #the inverse matrix (it it exists)! [10 -6 1] [ ] Ainv := [-2 1 0] [ ] [-7 5 -1] > x:=evalm(Ainv &* b); #yet another way, for nonsingular matrices, > #to solve Ax=b x := [1, -1, 1] > evalm(A&*Ainv); evalm(Ainv&*A); #just checking! [1 0 0] [ ] [0 1 0] [ ] [0 0 1] [1 0 0] [ ] [0 1 0] [ ] [0 0 1] > evalm(A^3); evalm(A&*A&*A); evalm(A+3*A); > transpose(A); > #matrix powers, multiplications, addition, > #transpose (what's that?) [ 45 82 40] [ ] [104 191 92] [ ] [180 338 157] [ 45 82 40] [ ] [104 191 92] [ ] [180 338 157] [ 4 4 4] [ ] [ 8 12 8] [ ] [12 32 8] [1 2 3] [ ] [1 3 8] [ ] [1 2 2] > 5) Now that you're comfortable with the basics of Maple, its time to take a look at your first assignment. Go to the class web page by following the links from my web page http://www.math.utah.edu/~oveliche. Open the pdf document Project1.pdf, or download the maple file Project1.mws.