# # # # Math 1080 # MAPLE AND CALCULUS # Monday March 1, 1999 # # INTRODUCTION TO THE LAB # We will be using a software package called ``MAPLE'', which does # mathematical computations. There are other packages which people use, # for example ``Mathematica'', and ``Matlab.'' U. students may buy # versions of MAPLE for their personal computers from the University # Bookstore, for something like $100. (You don't need to do that for # this course!). Commercial versions cost something like $800. The # competitors are priced similarly, I think. # # 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 handout 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 able to get a copy of # this Maple project from the www, 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. 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 1080 should automatically # have an account set up in our lab. These accounts are created from # University class lists. Sometimes happens that late-registering # people don't have accounts. 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 ask me, I should # have a list of your initial log-in names and passwords. If we can't # work out your data, we'll 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 very soon 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 a reasonable time interval, then your computer # account will be disabled for security reasons. Since it is already # late in the semester, you must take care of this soon. # # 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: At some time you # may want to go through the document Introduction to Xwindows in the # Lab There should be copies of this document at the back of the room. # Xwindows are like most windows in most ways; you want to be able to # open and close windows, resize them, move them about, and find them # if they happen to get hidden. You can also send and receive email from # your account here. There are several email programs available, # including ``mm'' and ``pine''. # For now, you should make two new windows, using your local # window: # # 2a) Make a NETSCAPE window by typing # netscape & # after the > prompt, and then hitting the () key. The # use of the ``&'' symbol keeps your local window active so that you can # use it for other things even while netscape is running. In some # number of seconds the outline of a new window will appear. If you # click on it it will turn into the browser netscape. I think it takes # you the the Mathematics Department home page http://www.math.utah.edu # but of course you can type in whatever internet address you desire and # go there. We will use the netscape window a little later. # # 2b) Make a MAPLE window by returning your cursor to the local window # and typing # xmapleV5 & # after the > prompt, followed by the key. The x is standing # for x-windows, the V5 for the current version of Maple which we are # using, and the & is for the same reason as when you made the netscape # window. Just as with the netscape window it will take a few seconds # for the outline of the maple window to show up, at which time you can # click on it to make it visible. # # 2c) Arrange your windows: Use your right-mouse button in the upper # quarter inch margin of each of your three windows to arrange them in a # way which lets you click on any one of the three margins, no matter # which window is in front. Then the easy way to move between windows # is to click on that upper margin (with the right mouse button) in # whichever window you want to be in. # # One or both of MapleV5 and netscape can be found by pressing the # correct button on your mouse, and then moving your mouse to highlight # the appropriate command. You may use either the Mouse method or the # command method. # # 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. # # 3) Math Department resources: (You may skip this step today but the # following information might be useful later.) 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. If you are interested in # Maple information, you can 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 at some point. # # # # # # 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, just as if you # were in another word processor. 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. MAPLE DOES NOT FORGIVE TYPOS. 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. This is a VERY common > # 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. # # So, you've already got calculators to do the sort of stuff I wrote # down above. But Maple does much more. Here are some Calculus # computations like we've been doing recently. # > diff(x^2,x); #``differentiate x^2 with respect to x.'' > #You better get 2*x! > diff(sqrt(x^2 +1),x); #a harder differentiation problem > #which you should be able to do using the chain > #rule. x ------------ 2 sqrt(x + 1) > f:= x-> sqrt(x^2 + 1); #this is the syntax for defining a > #function, in this case the function we just > #differentiated. In English, it is saying take x > #and make it go to the square root of x-squared > #plus one. 2 f := x -> sqrt(x + 1) > diff(f(x),x); #should get the same answer as before. x ------------ 2 sqrt(x + 1) > g:=x->cos(x^2 + ln(x)); #here's one you don't know how > #to differentiate 2 g := x -> cos(x + ln(x)) > diff(g(x),x); #but Maple does! 2 -sin(x + ln(x)) (2 x + 1/x) > int(x^2,x); #``integrate x^2 with respect > #to x'', means find the antiderivative of > #x^2, as a function of x. (Maple doesn't put in the > #integration constant, you will notice. ) > # You know the answer is x^3/3 + C > > int(x^2, x=0..1); #``Integrate f(x)=x^2, from > #x equals zero to one. This is our favorite > #integral. We know it represents the area > #under the graph y=x^2, from x=0 to x=1. > # We better get 1/3! # It is always a good idea to save your maple file periodically. # Do this now using the tool bar, under the File box (see the # instructions in the Introduction to Maple V.4 in the Undergraduate # Computer Lab handout if you need help.) The first time you save you # will be asked to enter a name for the file. You should make sure it # ends with .mws so that Maple can recognize it as a maple file. You # will notice that the .mws part is already written as part of the file # name to help you remember this. If you have a file you wish to modify # and rename you can use the ``save as'' option: it will make a copy of # the current file with whatever new name you specify. # It will probably happen some time that you will crash Maple long # after your last save. This will not make you feel happy. # # Exercise 1) Modify your file as indicated below, and then print out a # copy by following the directions. # 1a) 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 problems 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.) # 1b) Second, 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. # # Exercise 2) Another way to work with Maple is to start with something # off the www. In fact, a version of this project is available from my # home page. Put your cursor into the netscape window you made in step # 2 above. Click on the white region to the right of ``location'' in # the netscape toolbar. Enter the address # http://www.math.utah.edu/~korevaar This is my home page. You will # see stuff about our class, Math 1080. By clicking in the appropriate # places you could find current homework and a class syllabus. There is # also a header for our Maple project, click on it. This will send you # to the address http:/www.math.utah.edu/~korevaar/1080proj1.txt # You are going to save this file to your own directory for your # Math account in the lab. Do this by going to the ``file'' option on # the netscape toolbar and choosing the ``save as'' option. A dialog # box opens, and if you click ``O.K.'' at the bottom (without changing # the title of the file to be saved), netscape will save a copy of this # document in your home directory, with the name 1080proj1.txt. Do this. # Now return to your Maple window, go up to the ``file'' menu # option and choose ``open''. A dialog box will appear. In the menu # box, go to the ``filetype'' area at the bottom, click on the # upside-down triangle to the right to open your choices, and then # choose ``maple text'' with your mouse. This should make the # 1080proj1.txt choice appear in the big box. (That's why the file # ended with .txt, to tell Maple that it was a Maple Text document.) # Darken the 1080proj1.txt with your mouse and click on ``O.K.'' in the # upper right corner. A new window will appear inside your Maple # window, containing our project. You can switch between several open # Maple files by using the ``Window'' menu option at the top of your # Maple area. # # Exercise 3) Go into your 1080proj1 file and move your cursor to this # part of the project. Hit to go through the following # commands. They have to do with the area/integral concepts we've been # talking about. Understand what each command is doing. # > with(student):with(plots): #two useful libraries of commands which > #we have to ask Maple to open. There are many other libraries. > #The commands in ``student'' include the leftbox, leftsum commands > #which let us visualize the process of integration. The commands > #in ``plots'' include many plotting routines. > leftbox(1/x, x=1..2,10, color=blue,shading=orange); > #Do you see the syntax for this command? First you enter the > function, > #then the interval of x's (in this case from 1 to 2), > #then the number of boxes (in this case 10), then > #color options. Use commas to separate the various parts. > #You can find out more about commands by using the > #excellent ``help'' options at the top right of the menu bar. > leftsum(1/x,x=1..2,10);#compute the area of the boxes > evalf(%); #Find the decimal value of the last thing > #you computed > rightbox(1/x,x=1..2,10, color=green, shading=orange); > evalf(rightsum(1/x,x=1..2,10)); #get the > #decimal value of the area of the ``right'' > #boxes. (right upper corners touch graph) > (.6687714032 + .7187714032)/2; #average of left > #and right sums > int(1/x,x=1..2); #the integral of 1/x, from > #x=1 to 2. Is exact area value > evalf(%); #close to our approximation? # # Now might be a good time to save your file. You should make sure it # is saved as a .mws file. # # Exercise 4) Make right and left-box pictures, for the same function # y=1/x, and the same x-values, but with 100 boxes instead of 10. # Compute the right and left sums, and their average, and compare it to # the numerical value of ln(2). Remember, to insert Maple prompts into # a document use the ``[>'' menu option at the top of the maple window. # # The number called ``e'' is as famous and important as the number # called p. It is the z-value so that the area from 1 to z under the # graph of y=1/x equals exactly one. In other words, e is the number # which satisfies ln(e)=1. If we use left-boxes we over-estimate area # for y=1/x, and if we use rightboxes we underestimate it. So the # following pictures and computations show that e is between 2.5 and 3: > leftbox(1/x,x=1..2.5,10);leftsum(1/x,x=1..2.5,10); > leftsum(1/x,x=1..2.5,10); > evalf(%); > rightbox(1/x,x=1..3,10); > rightsum(1/x,x=1..3,10); > evalf(%); # # Exercise 5) Use left and right sums with 1000 boxes to show that e is # between 2.71 and 2.72. You probably don't want to make the left and # right box pictures with n=1000, however. By the way, e is the value # of the ``exponential'' function exp, at x=1, so you can get its actual # numerical value (to 9 decimal places) by typing > evalf(exp(1)); # Let's discuss p's value. The points (x,y) on the circle of # radius one, centered at the origin (the so-called ``unit circle'') # satisfy the equation x^2 + y^2 =1, by the Pythagorean Theorem. If we # solve this for y we see that the upper semicircle has equation > y=sqrt(1-x^2); # So if we estimate the area under this graph, from x=-1 to 1, we will # get half of the area of the unit disk, i.e. p/2. Thus we can estimate # p by multiplying the estimate by a factor of 2. Here's a picture with # 100 boxes: By the way, see if you can find the ``constrain'' menu # option, after clicking on your picture, in order to make your disc # look round instead of elliptical. > rightbox(sqrt(1-x^2),x=-1..1,100); > rightsum(sqrt(1-x^2),x=-1..1,100); > #the area of the boxes > 2*evalf(%); #an approximate value for Pi, twice the > #decimal value of the box area above. > evalf(Pi); #Maple understands Pi to mean the number Pi, > #and here is its value to 9 decimal places > int(sqrt(1-x^2),x=-1..1); #the exact value of the area, by > #the fundamental theorem of Calculus. # Exercise 6) Use 10,000 boxes in the rightsum formula to get a better # estimate for Pi. It might take a minute for Maple to do the # computation; it's kind of long. # Exercise 7) Use the ``save as'' option under the``file'' menu choice # to make a copy of this project, with the name ``proj1part2.mws'' and # then in ``proj1part2.mws'' use your mouse to remove everything before # Exercise 1, and everything after Exercise 7. (Highlight it and then # delete it.) Print out a copy of your solutions to the 7 exercises, to # hand in. Put your name at the top! (By using the `save as'' option # first you will have kept a copy of proj1.mws in your directory which # you can open from Maple whenever you want.) # # # Practice problems: Some of you requested additional problems on which # to practice antidifferentiation. Here are a few. If you use the # ``Int'' command (notice the capital I), Maple writes the integral # (which stands for antiderivative when no upper and lower x-values are # given), but doesn't evaluate it. You can get the antiderivative value # by using ``int'' (lower case i). Maple doesn't add the +C. For # example, here are both of them illustrated: # > Int(x^2/3 + 5*x +7,x); > int(x^2/3 + 5*x + 7,x); / | 2 | 1/3 x + 5 x + 7 dx | / 3 2 1/9 x + 5/2 x + 7 x # Here are some practice problems for antidifferentiation. You can make # up more, and check your answers using Maple. > Int(sqrt(2)*x^3 + 5/x^2 + 7*x^32,x); / | 3 1 32 | sqrt(2) x + 5 ---- + 7 x dx | 2 / x > Int((x+1)^2,x); / | 2 | (x + 1) dx | / > Int(5*x^3 -1/(5*x^3)+2,x); / | 3 1 | 5 x - 1/5 ---- + 2 dx | 3 / x # Here's a problem for finding area with the fundmental theorem of # Calculus. You could make up others: # Use the Fundamental Theorem of Calculus to find the area between the # graph of y=x(3-x) = 3x-x^2, and the x-axis, between x=0 and x=3. # Compare your answer to the approximation from boxes given with the # following commands: > rightbox(3*x-x^2,x=0..3,100); > rightsum(3*x-x^2,x=0..3,100); > evalf(%); # END