# Math 2250 # MAPLE TUTORIAL # Fall 2000 # # This document is a tutorial 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. The work you are to complete as your first # Maple assignment is the section 1.4 computing project, described on # pages 43-44 in the text. The MAPLE commands you will need in order to # do that project are reviewed in this tutorial. A precise template # for your project answers will be available on Friday September 1, and # will enlarge slightly on the Investigation a,b,c of page 44. # # 0) A preliminary word of Advice: Students often approach the task of # reading mathematical material as if they were reading a novel; they # sort of skim along quickly. That approach is O.K. to get an # overview, but in order to have a chance at real understanding you must # be prepared to proceed much more slowly, sentence by sentence and # thought by thought. Otherwise you will almost certainly find yourself # partly lost after several paragraphs and completely lost after several # more. (This might happen anyway.) If you are working properly it can # easily take half an hour to read through one page of mathematical # text. This takes a certain amount of discipline, patience, and # practice. With the Math 2250 computer projects there is the added # temptation of having Maple execute commands in successive command # sections by repeatedly hitting the enter (return) key, without # pausing to digest the interlaced text or the meaning of the commands. # There is a seductive appeal in having this capability. Resist it. # # We will assume 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. # # 1a) Logging in to a Math Lab machine: The Math Department Computer # Lab is located in the South Physics 205, i.e. inside the 2-story # brick building just north of the Math building JWB, and south-east of # the physics classrooms in the circular part of JFB. Room 205 is in # the back (East) of the building, on the second floor (from the west), # which equals the level of the ground on the uphill, east entrance. # 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 are available # on a table in the front 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. A window should appear which asks you to select a # server. Since the Math Department is sharing this lab with Physics, # there are physics and math server computers. You want to select one # from the list of choices which has ".math" in its name. If a # ".physics" computer is highlighted, use your cursor to choose one of # the ".math" computers, and 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.) # Your default 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 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 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. 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 in the front 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 current # (default) version of Maple is xmaple &, which you can type into a # local window, followed by . This is version 6, and you can # also find it as an option on one of your mouse buttons, it's your # choice. If you are using an earlier version of Maple (V5 or V4, for # example), there are slight # differences in commands and syntax, and they may confuse you once or # twice. # # 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 front 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 # mapleV6 window and a web browser window. # 3a) 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 Math # Department home page http://www.math.utah.edu/. By following links # from here you can find current and future course offerings, faculty # information, and much more. Since you are students, interested in # Maple information, click on "students" (at the upper left of the # page), and you are directed to http://www.math.utah.edu/ugrad/, the # undergraduate home page. If you choose "Undergraduate Computer Lab", # followed by "Selected software and tools", you will find some links to # Maple information. # 3b) More Information. Maple has its own introduction, as well as a # new user's tour, see item 5 below. # # 4) Maple: Move your cursor into the "Untitled" (new) 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 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 menue items. 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 ! ) 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, 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. 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. > 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, 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. If you need more help # saving your file see the instructions in the Introduction to Maple V.4 # in the Undergraduate Computer Lab handout at the front of the lab, or # ask an assistant. 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 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. # # 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 (which you can # pick up for free at the main Math office JWB 233) , 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 mapleV6 (and V5) 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. To keep the tour open but bring another window to the front, # use ``window'' menu item. # # 5b) Getting an on-line copy of this Math 2250 tutorial: (This is # also the process you will go through to get your project solution # templates.) This xeroxed tutorial is available as either # http://www.math.utah.edu/~korevaar/2250tutorial.txt or # http://www.math.utah.edu/~korevaar/2250tutorial.mws The first file is # in "Maple text" format, and will be easier to read from your browser. # The second file is in "Maple work sheet" format, and will look ugly in # your browser, but if you're lucky your own Maple will be able to open # it directly once you save it from the internet. The advantage of the # second format is that plots, formatting and output are reproduced # exactly as in your xerox copy. The disadvantage is that some # computers (not the ones in our lab) may not be able to understand it. # The advantage of the first format is that it is more universal. The # disadvantage is that Maple output and formatting may be lost. For # now, go to the first web address using your browser window. 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. (If you had saved the ".mws" version you could # open it as a maple worksheet.) # 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, related to your first project : You may # proceed now whether or not you created a copy of tutorial.txt in your # own directory and opened from Maple. # Reading the material on pages 43-44 you notice that you will # need Maple to draw a slope field for you. Recall this concept: First # order differential equations have the standard form dy ---- = f(x, y) dx # and their solutions are functions y(x) which make 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 did in section 1.3 of the text, # to see what graphs of solutions look like: Construct 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)], > ### WARNING: incomplete quoted name; use ` to end the name > [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. # Having played with these commands, could you figure out how to # make the slope field part of the picture on page 44? Of course, the # other resource you have is your computing projects book. # # 6) Commands for your actual first project: Let's try to make the # slope field on page 44. Using my resources I come up with the # following commands (see also the Computing Projects manual, pages # 3-5.) > with(DEtools): > deqtn:=diff(x(t),t)=.01*x(t) - .0001*x(t)^2; > dfieldplot(deqtn,x(t), t=0..1000, x=0..200); # If you want to include some solution graphs, you can use the command # DEplot, and get a picture like the one on the top of 44: # > DEplot(deqtn,x(t),t=0..1000,{[x(0)=.1],[x(0)=1],[x(0)=10], > [x(0)=100],[x(300)=150],[x(600)=150]},x=0..200, > colour=`black`,linecolour=`black`, > arrows=`line`, dirgrid=[30,30]); # # Now, you might recognize the DE in this problem as a separable one, # so you can actually solve it in closed form using the methods of # section 1.4, and this means Maple can solve it symbolically as well. # You can use the steps outlined on page 43, or you can directly use # dsolve: The following commands may prove useful for the actual # project: > dsolve(deqtn,x(t)); #general solution > dsolve({deqtn,x(0)=50},x(t)); #initial value problem > int(1/(x*(100-x)),x); #compute integrals as part of solving > #separable equations > convert(1/(x*(100-x)),parfrac,x); #do partial fractions.