# # Math 2250 # MAPLE TUTORIAL and PROJECT I HINTS # Fall 2001 # # This document is a tutorial for Math 2250 students who may not have # done previous work with MAPLE or in the Math lab, or who may just want # to brush up on their skills. At the end of the tutorial there is an # introduction to the first project. Links to the precise template for # your project answers and to an on-line version of this tutorial can be # found at the 2250-4 home page # http://www.math.utah.edu/~korevaar/2250fall01.html. # # The Math 2250 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 2250, 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 2250 purposes you need to be able to open Netscape (to # download files) and Maple (to work on them). Open Netscape 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, 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 > 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 xeroxed tutorial is available online in several formats, if you # follow the links from the 2250-4 homepage # athttp://www.math.utah.edu/~korevaar/2250fall01.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 2250falltut.mws file to your # home directory. # # Now return to your Maple window and use the ``file'' menu item to open # 2250falltut.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. # # 4) # INTRODUCTION TO PROJECT I # # A preliminary paragraph 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. # # Open your text book to page 55, and follow along. We will go through # the Maple commands and text corresponding to the section 1.5 Computing # Project of Edwards-Penney. If you go through this section carefully # now, then your life should be relatively easy when you download the # solution template from the course home page. Make sure you understand # what each command is doing, and what each equation is saying, in the # work below. # # For further information about syntax and options related to commands # below, use the help menu button at the upper right corner of your # Maple window. # > restart: #When you start new work it is often a good idea > #to clear all old definitions etc. restart does this. > #Of course, then you must then reload any packages you need > #and redefine anything you need as well. > with(DEtools): #load diffeq tools, for later. If you want > #to see the list of commands in the DEtools > # package, end your command with ";" rather than ":" # # At the start of the the project, on page 55, we see how to automate # the method of solving a general first order DE initial value problem, # see equation (11) on page 48. So P(x) and Q(x) will be as shown # there, except we will use lower case p and q like on page 55. On # page 55 we are considering the particular first order linear # differential equation # > deqtn:=diff(y(t),t) + y(t) = t; > #notice how we write the derivative of y > #with respect to t /d \ deqtn := |-- y(t)| + y(t) = t \dt / # # Following the algorithm on page 48 (with the roles of x and t # reversed as on page 55!) the text tells us to set > p:=t->1; > #this is how to define functions in Maple; > #the command is saying p(t)=1. The := should > #be read as "is defined to be." The arrow > #can be thought of as saying "goes to" > q:=t->t; > #this command is saying q(t)=t > r:=t->exp(int(p(x),x=t0..t)); > #the integrating factor r(t) > y:=t->(1/r(t))*(y0+int(r(x)*q(x),x=t0..t)); > #the solution y(t) to the IVP with y(t0)=y0. # # For example, if we wanted to solve the differential equation on page # 55, with y(0)=2, we would set > t0:=0; > y0:=2; > # and evaluate > y(t); 3 + exp(t) t - exp(t) --------------------- exp(t) You might want to verify this answer to the initial value problem by hand. Of course Maple can solve DE's symbolically too, with the single command "dsolve." If you want to read about the syntax required for this command, you should use the Help menu item at the upper right corner of your Maple window, and search the topic "dsolve". Once you have a rough idea about a command it is often helpful to scan down to the bottom of the help file to see worked out examples. If you do this you will eventually decide to try something like > dsolve({deqtn,y(0)=2},y(t)); Error, (in pdsolve/sys/info) required an indication of the dependent variables in the given system # This command didn't work. It would've worked, except that you have # defined y(t) just above here, so when Maple evaluates the differential # equation "deqtn" which you defined earlier, it plugs in the y(t) you # defined subsequently, so that the deqtn evaluates to t=t, yielding the # error message. ???!!!! You can fix problem by never using the same # symbols twice, or more practically, by restarting, to clear out # conflicting defintions: > restart: #clears all definitions and memory > with(DEtools): # Restarting and Reopening: Every time you reopen a Maple file you will # neet to re-enter commands and definitions. Similarly, if you restart # but want some old definitions to hold, move your cursor to the # appropriate command fields and reenter them using the key.. > deqtn:=diff(y(t),t) + y(t) = t; > #I moused in same deqtn from above > dsolve({deqtn,y(0)=2},y(t)); > #and same dsolve command above. Now > #it should work, and even give an answer > #which agrees with your ealier one /d \ deqtn := |-- y(t)| + y(t) = t \dt / y(t) = t - 1 + 3 exp(-t) # # We now continue with the book's discussion at the top of page 56. # > A:=t->a0 + a1*cos(omega*t) + b1*sin(omega*t); > #formula for ambient temperature, with free > #parameters a0, a1, b1, omega. This is equation > #(1) on the top of page 56. When you enter multi-line > #commands hold down the shift key while you hit > #"enter" or "return", to prevent premature execution A := t -> a0 + a1 cos(omega t) + b1 sin(omega t) > deqtn3:=diff(u(t),t)=-k*(u(t)-A(t)); > #we name our DE "deqtn3" since it's equation (3) > #on page 56. deqtn3 := d -- u(t) = -k (u(t) - a0 - a1 cos(omega t) - b1 sin(omega t)) dt # We will find the general solution to deqtn3 first, with all the free # parameters, and then fix the parameters for a July day in Athens # Georgia second. You should be able to use the integral table entries # 49,50, or alternately have the computer follow the recipe method we # just outlined to find the general solution. However, it is easier to # just use dsolve. You should verify that the solution you get below # agrees with equation (4) on page 56. > eqtn4:=dsolve({deqtn3,u(0)=u0},u(t)); eqtn4 := u(t) = - exp(-k t) 2 2 2 2 2 (k a1 - k b1 omega + a0 k + a0 omega - u0 k - u0 omega ) / 2 2 2 2 2 / (k + omega ) + (a0 k + a0 omega + k a1 cos(omega t) / + k a1 omega sin(omega t) - k b1 omega cos(omega t) 2 / 2 2 + k b1 sin(omega t)) / (k + omega ) / # Now we set the parameters equal to the values at the bottom of page # 56, so that we are studying something like summer days in Athens # Georgia: > a0:=80; > #average ambient temp in Georgia in July > a1:=-5; > b1:=-5*sqrt(3.0); > #the a1 and b1 values were worked out by hand, > #using the cosine addition > #angle formula, assuming 4 a.m. temp min and 4 p.m max, > #and range from 70 to 90 degrees, > #for trigonometric temp oscillation. > omega:=Pi/12; > #this makes the period equal to 24 (hours) > k:=0.2; > #constant for a well-insulated building > # # With these parameter values, we get equation (5) on the bottom of page # 56: # > eqtn5:=simplify(eqtn4); > #It automatically plugged in the parameter > #values I defined above. I asked for "simplify" > #because otherwise the expression looked too messy. > # eqtn5 := u(t) = -82.33510564 exp(-.2000000000 t) + 80. + exp(-.2000000000 t) u0 + 2.335105624 cos(.2617993878 t) - 5.603607924 sin(.2617993878 t) # # Read along with the text on page 57. Notice that no matter what the # initial house temperature was, the negative exponential terms die out # rapidly and one is left with the steady periodic solution given by # equation (6) in the text. We can extract it from our eqtn5 above, by # using the mouse to cut and paste: # > usp:=t-> 80 + > 2.335105624*cos(.2617993878*t)-5.603607924*sin(.2617993878*t); usp := t -> 80 + 2.335105624 cos(.2617993878 t) - 5.603607924 sin(.2617993878 t) # We can reproduce figure 1.5.10 (it would take more work to get all # the labels in) as follows > with(plots): > #this is the plotting package. End with ; > #to see command list Warning, the name changecoords has been redefined > ambient:=plot(A(t),t=0..50, color=red): > #this is a plot of ambient temp defined > #above, with Athens parameters. Make sure > #to end this command with colon, not semicolon, > #or you will get a very long list of points. > inside:=plot(usp(t),t=0..50, color=black): > #the steady periodic inside temperature > display({ambient,inside}, title="inside-outside"); > #display both plots together # As the text remarks, you see that the inside temperature oscillates # trigonometrically with a smaller amplitude and with a time delay, # relative to the outside temperature. (The annual seasonal temperature # variations on earth lag behind the solstice-equinox dates, for a # similar reason.) # # We can recover figure 1.5.9, together with the slope field, with a # DEplot command. This picture illustrates geometrically the fact that # all solutions converge to the steady periodic one: # > DEplot(deqtn3,u(t),t=0..50,{[u(0)=65],[u(0)=70], > [u(0)=75],[u(0)=80],[u(0)=85],[u(0)=90],[u(0)=95]}, > arrows=line, color=black,linecolor=black, > dirgrid=[30,30], stepsize=1, > title="inside temperatures"); # This is the end of the tutorial. To download your instrucitons and # template for project 1, follow the links from # http://www.math.utah.edu/~korevaar/2250fall01.html.