# Math 2270 # MAPLE TUTORIAL # September 2001 # The purpose of this tutorial is to get you going with MAPLE, # probably in our Math Lab. You can follow this tutorial to log onto # the Math Lab machines, familiarize yourself with how they operate, # 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 eperience you may want to skip # various sections. # Your actual Maple assignment can be found by going to the Maple # page from our course homepage, at # http://www.math.utah.edu/~korevaar/2270fall01.html. (This tutorial # lives there too.) # Our class projects can be done in versions five and above of # Maple, with minor changes. The Math Lab uses version 7, whereas the # EMCB and Marriott Labs have version 6. A student version of Maple for # home computers is available from the bookstore for approximately $100. # # 1) Using the Math Computer Lab: # The Math Department Computer Lab is located in the South Physics 205, # i.e. on the East (uphill) end of the second floor of then brick # building immediately north of the Math building JWB. Room 205 is just # inside the East entrance. Until construction of the new Math Center # is complete this winter, Physics and Math share this lab. Useful # information about most aspects of the lab can be found by following # links from the Math Department web pages, e.g. starting at # http://www.math.utah.edu/ugrad/lab. You can find out about X-windows, # Unix commands, Maple, Netscape, file editing, mail, etc. # # 1a) Logging on: # Almost all students who are registered in Math 2270, or in any other # math class, will already have accounts set up in our lab. Since # these accounts are created from University class lists, # late-registering students may not be accounted for. If you fit in # this case the lab assistant can help you apply for an account - # provided you have brought your student I.D. to show that you are a # University student. # The lab machines are left on - move the mouse or hit a key to # wake yours up. There are two possibilities for the dialog box which # appears. # # (A) If you get a dialog window asking you to "select a server to log # on to", use the mouse to select one which has ".math" in its name. # Then O.K. your choice by clicking in the "accept" box. In a few # seconds a login window should appear, asking for your login name and # password, and have "Mathematics" written in red on the top. (If the # login window says "Physics" you have accidently chosen a physics # server, and you should type "control C" to go back to the previous # step.) # # (B) If instead you get a dialog window which says "Welcome to # Orion", highlight "options" with your mouse, and from its submenu # choose "remote login" and then "choose host from list". This will get # you the window in (A), from which you proceed as above. If you are # confused, ask the lab assistant. # # Your login name is made out of your initials. If your name is Karl # Fred GausS, then your login name is c-gskf, following the recipe: # c-(first letter of last name)(last letter of last name)(first letter # of first name)(middle initial). If there are multiple people # registered this term with the same initials, then rather than c-gskf, # they are assigned login names with a numerical suffix, c-gskf1, # c-gskf2, c-gskf3, etc. Mr. Gauss would not know beforehand which case # he fell into, so would probably try c-gskf first, followed by his # password. In case of failure he would then try c-gskf1, then c-gskf2, # etc, through c-gskf4. Then he would find a lab assistant. After # entering your try at a login name, type the ``return'' key and the # cursor should be in the password box. # # Your initial password is just the gskf part of your login name # followed by the last four digits of your student I.D. number. If Mr. # Gauss has ID number 000735421 then his initial password is gskf5421, # regardless whether his login name was c-gskf or c-gskf3. If the # login fails try again and then try the different login names suggested # above. One possibility is that your account was created using your # social security number (which used to be used for student ID number). # If failure continues find a lab assistant and he/she will help you. # # Once you are logged in successfully a ``local'' window should appear. # Notice that it has various parts: borders on the top (title bar), # borders on the side (scroll bar), etc. If you move your mouse on its # pad your pointer (called cursor) moves around the screen. If you want # to work in a window, the cursor should be in it. You can make # multiple local windows by pressing the right mouse button and # highlighting "local". # # 1b) Changing password: Some time within the first several weeks of # classes you must change your default password into a personal one. # You do this as follows: Get your cursor into a local window. Type the # unix command passwd, followed by return, and follow the directions. # Your new password should be exactly 8 characters long. Don't choose a # word in the dictionary or a proper name. Composites of dictionary # words, like strawdog, are good. Even better is to use one or two # upper case letters, e.g. strAwdog. For still more security, use some # digits, e.g. strAw4o9. It takes about 15 minutes for a new password # to take effect. If a password is not changed within the first several # weeks of class, then your computer account will be disabled for # security reasons. Make sure to write down your password in a secure # place, in case your memory is not perfect. # # 1c) Logging out: Move the cursor out of all windows (into the # background), press the left mouse button and choose the last menu # item: Exit X-Windows. (You probably don't want to do this now, but at # least locate the menu item for later.) # At this point you are ready to get used to the X-windows: # # 2) 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 idiosyncracies, 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 your 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 pages at # http://www.math.utah.edu/ugrad, and follow the links to explore # computer lab information. # # Finally, open a Maple window one of two ways: from the middle mouse # button you may choose xmapleV7, or you can type the command xmaple &, # followed by , into a local window. The Math Department's site # license for version 7 of Maple only allows a certain number of people # to use it at once. If this number is exceeded you won't be able to # run version 7, but you can use the Mouse to open xmapleV5.1, for which # our site license allows unlimited use. # # # 3) 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 mapleV6 or mapleV7 (worst case V5) # 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. If you are # doing a homework assignment 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 Math # 2250 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 in step (2). 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. > > (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. > (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. > diff(x^2,x); #``differentiate x^2 with respect to 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 .5112814089 > Pi;exp(1);evalf(Pi);evalf(exp(1));infinity; > #some important numbers # # # 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 haven't # 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. For more information about # this, go to http://www.math.utah.edu/ugrad/helpforunix.html. # # 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 # diamond, followed by ``enter'' or by a click on the print box at the # bottom of the window, a paper copy will come out of one of the # printers at the side of the lab. Do this now. Alternately, if you # want to use a different printer, you can use the output to file # diamond 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 printers from a local window, the command # would be "lpr -P b129lab1", or "lpr -P b129lab2", followed by the # return key. You do not put in the quote marks, but you are careful to # leave spaces exactly as indicated. The lpr stands for line printer, # the -P stands for print, and the b129lab1 or b129lab2 are the names of # the two printers. If you have trouble printing ask a lab assistant # for help. # # Downloading Maple documents: # This document is available online in several formats, if you follow # the links from the 2270-2 homepage # athttp://www.math.utah.edu/~korevaar/2270fall01.html. Files with # suffix ".mws" or ".txt" can be downloaded from your browser and then # opened from Maple. 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. # # Go to the course homepage address using your browser, follow the link # to the Maple page, and find and save the 2270proj1a.mws file to your # home directory. # # Now return to your Maple window and use the ``file'' menu item to open # 2270proj1a.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 # ``2250tutorial.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. # # # 4a) 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 # didn't know them already, or if I wasn't 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 # # 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. # # 4b) 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 > A[2,3]; #one of the entries of A > b:=vector([1,1,-3]); #the right-hand side for > #a linear system Ax=b > augAb:=augment(A,b); #the augmented matrix > C:=rref(augAb); #compute the reduced row echelon form > #of the augmented matrix > x:=col(C,4); #read off the solution vector to Ax=b > 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 *.) > x:=linsolve(A,b); #another way to solve linear systems. > Ainv:=inverse(A); #the inverse matrix (it it exists)! > x:=evalm(Ainv &* b); #yet another way, for nonsingular matrices, > #to solve Ax=b > evalm(A&*Ainv); evalm(Ainv&*A); #just checking! > evalm(A^3); evalm(A&*A&*A); evalm(A+3*A); > transpose(A); > #matrix powers, multiplications, addition, > #transpose (what's that?) # #