# Math 2250 # MAPLE TUTORIAL # Spring 1999 # # This tutorial is for Math 2250 students who may not have done # previous work with MAPLE or in our lab, or who may just want to brush # up on their skills. Steps (1) and (2) are written assuming you are # working in the Math Department computer lab. If you are in another # lab (e.g. Engineering lab in EMCB or Library lab in Marriot) or on # your own computer, you will get started differently. # # 0) A word of Advice: Often when faced with reading mathematical # material students will try to do it as if they were reading a novel: # sort of skimming along quickly. This is O.K. to get an overview, but # in this tutorial and when you try to read your text, you must go # slowly, sentence by sentence, making sure that you understand the # import of each statement before moving on to the next one. Otherwise # you will find yourself completely lost after several paragraphs. If # you are reading properly it could easily take 20 minutes to get # through one page of mathematical text. This takes a certain amount of # discipline, patience, and practice. You will be copying the Maple # projects for this course from www addresses, and you will be able to # have Maple execute various commands just by hitting the enter (return) # key. There is a seductive appeal when you have this capability of # zipping through the textual comments and the Maple commands. Resist # it. # # 1a) Logging in to a Math Lab machine: The Math Department Computer # Lab is located in Building 129, the small, 1-story plus basement, # off-white building immediately east (uphill) from the Math building # JWB on president's circle. (There are two such buildings, you want # the one closest to JWB.) The lab is at the north end of the upper # floor. (So the Engineering Math tutoring room is at the opposite # end.) The following information about logging in and your initial # password is summarized from the handout Introduction to the # Undergraduate Computer Lab Department of Mathematics, University of # Utah, SLC, Utah 84112 . This and other useful handouts should be # available on a table at the back of the lab. # Everyone who is registered in Math 2250 should automatically # have an account set up in our lab. These accounts are created from # University class lists so it sometimes happens that late-registering # people don't have accounts yet. If you turn out to be one of these # people you will need to consult the lab assistant about getting an # account. Make sure to bring your student I.D. because the first thing # the assistant must do is verify that you are a University student. # If your machine looks asleep jiggle the mouse or hit any key to # wake it back up. If necessary type a ``return'' (or ``enter'') key # to get the cursor into the ``login name'' box. Your login name is # made out of your student I.D. number and your actual name, as follows. # All names from classes begin with ``c-''. 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 who would have the same login name, say c-gskf, then they are # instead assigned login names as 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 c-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. Another possibility (at least in the fall term) 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. # # 1b) Changing password: Sometime within the first two 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. Note that it takes about 30 minutes for a new # password to take effect. Also, you should be aware that if a password # is not changed within the first two weeks of class, then your computer # account will be disabled for security reasons. # # 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: Go through the # document Introduction to Xwindows in the Lab, which you should have a # copy of. There should also be copies of this document at the back of # the room. Xwindows are like most windows in most ways; your aim here # is to experiment to see how to open and close windows, resize them, # move them about, and find them if they happen to get hidden. When you # get to the end of the document you should also have opened a NETSCAPE # window and a MAPLE window. Note: The command for the most recent # version of Maple is xmapleV5 &. You can also find version V5 of # Maple as an option on one of your mouse buttons, it's your choice. # Don't use mapleV4 or other earlier maples, since the software changes # with each successive version. # # Further information: If you want more in-depth information about the # computing facilities in this lab, you might pick up a copy of the # handout A Crash Course on CSC Facilities, from the back table. # # # # # # If you are starting the tutorial at this point (because you're doing # it on your own at another location), you should have opened a mapleV5 # window and a web browser. # 3) Math Department resources: There is introductory material about # Maple on our web pages. If you wish to see what's available use the # browser window you made in step (2) above, and go to the departmental # home page http://www.math.utah.edu. There is a wealth of information # and links on this page. You can find current and future course # offerings, faculty information, and much more by opening the various # links with your mouse. Since we are interested in Maple information, # use the scroll bar to move down the home page until you find the # computing box, near the major heading More Information. (If the web # page changes in the future, some of these directions may no longer be # exactly correct.) Click on the computing box link, and you will # automatically go to the address # http://www.math.utah.edu/computing.html If you click on the Maple box # you will be led to various introductory information. You may want to # look at it later. There is also an introduction to Maple called # Introduction to MapleV.4 in the Undergraduate Computer Lab, located at # the web address http://www.math.utah.edu/lab/ms/mapleV4-intro.html # (even though we are using V5). There may be paper copies of this # document at the back of the lab. You may want to refer to either the # on-line or paper copy. # # 4) Maple: Move your cursor into the Maple window which you created # in step (2). 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. To insert text click on the ``T'' box. You # can use the mouse to cut, paste, and edit a document. In fact, this # document you are reading is a Maple document even though it is largely # text. # To give you a flavor of what Maple can do, we will try a few # commands. They should begin on a line 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 mess up your 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. 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 ! ) # > 3+4; 4+5: 6 * 7; #one of these computations will not be shown > #even though all three will be done, illustrating the > #difference between a semicolon and a colon > > (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; #this is the syntax for defining a > #function, in this case the function we just > #differentiated > diff(f(x),x); #should get the same answer as before. > int(t^2*exp(t),t); #``integrate (t^2)*exp(t) with respect > #to t'' (Maple doesn't put in the integration constant.) > > int(t^3*exp(sin(t)),t); #this shows that Maple is not God, you > #will get / | 3 | t exp(sin(t)) dt | / > # since if Maple can't find an elementary function > #antiderivative it just echos what you put in. > 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 > > sum(3^(-n),n=1..100); #add a geometric series part way, > #this is the series 1/3 +1/9 +1/27 + ... > evalf(%); #get its decimal value. The symbol % refers to the > #last thing which Maple has computed, the command evalf > #gets its numerical value > > Sum(3^(-n),n=1..infinity); evalf(%); #add the series > # all the way to infinity. Sum with captial > #S writes the sum but doesn't evaluate it, > #but then evalf(%) does. > Sum((.001)*(n/1000)^2, n=1..1000); evalf(%); > #This is a Riemann sum for the integral of x^2 > #from 0 to 1, with 1000 equal subdivisions. > #Sum with capital S writes the summation, but > #doesn't evaluate it. evalf(%) gives its value. > int(x^2,x=0..1); #this is the exact value of the same integral > > Pi;exp(1);evalf(Pi);evalf(exp(1));infinity; > #some important numbers # # It is always a good idea to save your maple file periodically. Do # this now using the tool bar (see the instructions in the Introduction # to Maple V.4 in the Undergraduate Computer Lab handout if you need # help.) It will probably happen some time that you will crash Maple # long after your last save. This will not make you feel happy. # Now we will see how to print a hard copy of our file. First, # scroll to somewhere in your worksheet and add some text with the ``T'' # menu item. Maybe scroll to the top and put 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. # Now, 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 in the little room at the back 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. # # 5) Differential Equations, 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 differential equations? An answer for DE's can be # obtained by perusing your Computing Projects textbook, but it is also # 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. # # 5a) In mapleV5 (but not in mapleV4) there's an online tutorial # Click on the ``Help'' box, and then on the choice ``New User's # Tour''. Probably this tour will superimpose onto your current Maple # session. Or maybe you can't see the new tour because its hidden # behind your current window. In the latter case use the ``window''menu # option to change windows. The tutorial gives examples from many # areas of mathematics, including differential equations, which you can # peruse at your leisure. In this tour you will be able to put your # cursor onto any command line, type return, and see what the command # does. 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, or use an option in the ``window'' box. # # 5b) Getting an on-line copy of this Math 2250 tutorial: The web # address of this xeroxed tutorial is # http://www.math.utah.edu/~korevaar/2250tutorial.txt You may use your # browser window to view it, and to get a copy of it which you will then # open in Maple. Go to this web address now, using your browser window. # (This is the way you will want to do your Math 2250 projects, because # it will save you huge amounts of typing time.) If you're using # netscape as your browser, pick the ``file'' menu option, choosing # ``save as''. Unless you give another name for it you will now save # this document with the same name it has on the web, namely # ``2250tutorial.txt''. It creates a copy of this file in your home # directory. Do it. # Now return to your Maple window and use the ``file'' menu item to # open``2250tutorial.txt''. 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. # 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 can insert new prompts or new text # wherever your cursor is, by using the > or T buttons on your toolbar. # # 5c) An example of help : You may proceed whether or not you created # a copy of tutorial.txt in your own directory and opened from Maple. In # future projects you will want to work off of the web, however, as # indicated in (5b). # Let's illustrate some material from chapter 1 of our text, and # the usefulness of help windows Recall, we are dealing with first # order differential equations and we will assume they have the standard # form dy ---- = f(x, y) dx # A solution is a function y(x) which makes this equation true. # Geometrically that means that if y(x) is a solution, and if you plot # its graph in the x-y plane, then the slope of the graph at each point # (x,y(x)) is given by the formula f(x,y(x)). One can therefore work # backwards, and this is what we do in section 1.3 of the text, to see # what graphs of solutions look like, by constructing slope (directions) # fields: at a representative number of points (x,y) in the plane plot # short segments having slopes f(x,y). If you plot enough slopes you # will be able to sketch in solution curves to the DE. The resulting # picture is called a slope field or a direction field. Let's use # Maple to illustrate these ideas. # Does Maple have commands to draw slope fields, to solve general # differential equations, to graph the solutions?????? OF COURSE!!!!! # Let's try to find them. # Click on the Help option at the upper right corner of your Maple # window. A little window opens with further choices. Pick the ``using # help'' option. Thus so far you have done help/using help. You may # need to change windows (menu item) to see the help window. Then in # the grey box at the top left, click on ``Mathematics''. Then make # successive choices so that you create the chain # Mathematics/Differential Equations/DEtools/plotting/dfieldplot. This # final word is actually a Maple command to make pictures of direction # fields. For many queries, this table of contents approach to getting # help ususally works best, but you can also use the ``topics search'' # or ``full text search'' options at the top level of help. # If you now read about the command dfieldplot, you will see that # it seems to plot direction fields for first order DE's, among other # things. Often you can get an idea of how a command works by skipping # to the end of the help file and copying one of the sample commands # into your own worksheet. For example, use your mouse and menu options # now to copy the block of commands from the end of the dfieldplot help # file and paste them into your worksheet. Then execute the entire block # by getting your cursor anywhere into the block and typing ``return''.: # The block you are getting should look something like (you don't want # to type this in by hand!): > > with(DEtools): > dfieldplot([diff(x(t),t)=x(t)*(1-y(t)),diff(y(t),t)=.3*y(t)*(x(t)-1)], > [x(t),y(t)],t=-2..2,x=-1..2,y=-1..2,arrows=LARGE,title=`Lotka-Volterra > model`, color=[.3*y(t)*(x(t)-1),x(t)*(1-y(t)),.1]); > dfieldplot(diff(y(x),x)=1/2*(-x-(x^2+4*y(x))^(1/2)),y(x),x=-3..3,y=-3. > .2, > title=`Restricted domain`,color=1/2*(-x-(x^2+4*y))); # You should execute this block. You will find that there were three # commands in it: the first one, ``with(DEtools):'' loaded a library of # tools for solving differential equations. If you had ended this # command with a semicolon instead of a colon Maple would have listed # all the commands it was loading from this library. You can find out # more about all of these tools by using the help files if you wish. # Then there are two plotting commands. The first one creates a # ``velocity'' vector field (with fat arrows) in the plane for a system # of two first order differential equations, apparently called the # Lotka-Volterra model. This is also sometimes called a predator -prey # system, see chapter 6.3, page 360 for a similar picture. The second # picture is closer to what we want. It is a direction field for the # differential equation > diff(y(x),x)=1/2*(-x-(x^2+4*y(x))^(1/2)); d 2 -- y(x) = - 1/2 x - 1/2 sqrt(x + 4 y(x)) dx # The reason Maple only draws slopes above a certain parabola, is that # the slopes are not defined as real numbers below it, as you can see # from the right side of the above formula. Looking at the commands # gives you an idea of the syntax which is used. More specific # information can be found in the complete help file. For example, the # command which draws the last plot clearly has a place to put the DE, a # place to put the x and y range of the picture, and there seem to be # various other options available as well. # 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 # workstation. Or you can keep them around and return to your worksheet # with the ``window'' menu option. # # 6) Doing some actual problems on Maple, section 1.3: Let's try to # make the slope field and draw the trajectories for problem #3 on page # 24. Using my resources I come up with the following commands (see # also the Computing Projects manual, pages 3-5.) > > with(DEtools): > deqtn:= diff(y(x),x)=y(x)-sin(x); > dfieldplot(deqtn,y(x),x=-3..3,y=-3..3, arrows=line, dirgrid=[30,30]); # Now, according to page 5 of the Edwards-Penney Computing Projects book # there is a command ``DEplot1'' which will simultaneously plot a # collection of solutions, and the direction field, for a first order # DE. You can try that command; it doesn't work for me, however, nor # does it seem to be in our Maple. You can use the more basic command # dsolve to solve initial value problems one by one, however, or DEplot # to plot them. (If you're a good Maple programmer you could write a # subroutine for DEplot1.) by the way, you might recognize the DE in # this problem as a linear one, so you can actually solve it in closed # form using the methods of section 1.5, and this means Maple can solve # it symbolically as well: > dsolve(deqtn,y(x)); # Notice how Maple writes constants. We can also solve initial value # problems: > dsolve({deqtn,y(0)=0},y(x)); # You can plot the solution either by extracting the right side of the # formula above, and using a plot command, or by using DEplot directly. # For example, try the following command, and you should get the picture # below it. (Remember to use ``shift-return'' to give multi-line # commands.) > > DEplot(deqtn,y(x),x=-3..3,{[y(0)=0],[y(0)=1]},y=-3..3, > colour=`black`,linecolour=`black`, > arrows=`line`, dirgrid=[30,30]); # At this point it should be clear to you that the computer could make # nice pictures for the problems in section 1.3. And you should be # ready to try any other computer exercises from chapter 1 and the # computing manual that interest you.