MATH 1170 MATHEMATICS FOR LIFE SCIENTISTS Introduction to Maple 1 Getting Started Logging in: This is what you do to start working on the computer. If your machine seems to be asleep, jiggle the mouse to wake it up. If necessary, hit the "enter" key to get the cursor into the "login name" box. If it says something about physics, raise your hand to get help { it needs to be a math machine. Your login name is made as follows: All login names from classes begin with \c-". If your name were Wolfgang Amadeus Mozart, your login name would be c-mtwa, following the recipe of c-(rst letter of last name) (last letter of last name)(rst letter of rst name)(middle initial). (If you don't have a middle name, your login will only have 3 initials, i.e. c-xxx). If there is more than one person registered during a semester who would have the same login name (say c-mtwa), then they are assigned the login names c-mtwa1, c-mtwa2, etc. Check the list at the front of the lab to nd your login if this is all too complicated. Your initial password is the mtwa part of your login name followed by the last four digits of your student ID number, not your social security number. For example, if Herr Mozart's student ID number was 000001234, his initial password would be mtwa1234. It would be the same regardless of whether his login name was c-mtwa or c-mtwa3. The local window: After a delay, long or short depending on processor speed, system, load, phase of moon, etc., a window named local will appear. Notice that it has various parts: borders on the top (title bar), borders on the side (scroll bars), etc. The mouse and cursor: When you move the mouse around, it moves a pointer on the screen. This is called the cursor. Move the cursor now. Notice how it changes shape as you move inside the window, then move outside to the \background." Notice also how the cursor changes shape as you move it to various parts of the window. Logging out: Just as important as logging in is logging out. You do this when you nish work (or when you leave the room). To log out, move the cursor to the background, press the left mouse button, and choose the last menu item: Exit X-Windows. Don't do this now, but be aware of how it is done. You will need it later. 2 Basic window stu Disappearing windows: If you click on the title bar with the left mouse button, it will disappear. Actually, it is still there in miniature form. Look at the top of the screen. Both on the left and right you will see little rectangles labeled local. Clicking on such a rectangle with the left mouse button causes the window to reappear. Practice making windows disappear and reappear. 1 Typing: To type something, the cursor must be inside a window. Put it inside the local window and type whoami. Put it outside the local window (on the screen background) and type the same thing. Did you notice a dierence? In the rst case you successfully gave a command to the computer, which (of course) obeyed. Practice typing commands. Opening netscape: Bring the local window to the front, and type the command netscape & in your local window. The little & at the end of the line runs the program in the \background," meaning that you can issue other commands simultaneously. The ghost of a new window will appear in a kind of \dotted outline form." Move the mouse to position it and click with left mouse button when satised. Move the mouse from one window to another. Observe the change in appearance of the title bar. A dark bar indicates an active window. If your active window is behind another window, press the F2 key to bring active window to front. Practice this. Moving windows: Press on the title bar with right mouse button, drag to new position, and release. Practice! Resizing windows: Press on square in upper right corner of window with right mouse button, drag, and release. Practice! 3 Maple Maple is kind of super graphing calculator. It can help with a wide variety of problems | arithmetic, algebra, trig, graphing, calculus, etc. It can also solve many kinds of equations. To open it, type the command xmaple & in your local window. It will open a new window just like the netscape & command did. Arithmetic in Maple Try these calculations: > > > > 5 + 2; 5*2; 5^2; 5 - 2; # asterisk denotes multiplication # caret denotes a power (exponentiation) Every Maple command must end with a semicolon. Otherwise, your command is ignored. Maple is very nicky about such things. The stu after the \#" is a comment { it will be ignored by Maple but can be useful to help you remember what you were doing or in communicating with others. Use the slash to indicate division, as in > 5/2; The result is perhaps not what you would expect: Maple likes to keep things in exact form if possible. However, if you use decimal numbers (like a good scientist), you get decimal answers: 2 > 5.0/2.0; > 2.1^10; You can use parentheses in the normal way: > (5.0 - 2.1)/(3.73 + 4.1); Maple can do huge calculations without batting an electron. > > > > > 100!; 2^100; Pi; evalf(Pi); evalf(Pi, 100); # 1 x 2 x 3 x .. x 99 x 100 # stays in exact form # converted to decimal The evalf function converts things to \oating point" form. In the last example, it converted (typed Pi in Maple) to a precision of 100 digits. Here are a few more arithmetic problems: > 21229/31993; > ifactor(12345678987654321); # factor into primes Editing in Maple You can pick up a line by darkening it in with the left mouse button. To paste it, click on the spot where you want it (with the left mouse button again), and then click the middle button. If you want to change something in the line, use the mouse to nd the spot you want, and then delete and add characters where the mouse is. Algebra in Maple Unlike many calculators, Maple can do algebra. Try the following: > > > > m := 3.12; a := 4.6; m*a; m := 2; m*a; Notice that you assign a value to a variable using the special command \:=" and not just \=". Maple is also nicky about this. Maple can solve many algebraic equations. To solve 2x + 5 = 8, type > solve(2*x+5=8,x); This tells Maple to solve the given equation for x. To get the answer in decimal form, put in some decimal points. Make up a quadratic and test Maple's algebra. It is essential to use the little * for multiplication { Maple does not know what to do with an expression like 2x. 3 Graphing Consider the function f (x) = x(1 ? x): To graph it on the interval 0 x 1, type: > plot(x*(1-x),x=0..1); A graph should appear just below the command. To change its shape and size, click on it, and then grab the square points on the sides and corners with the left mouse button. After clicking on it, you can change some of its properties with the \format" and \style" pull-down menus at the top. Try to make your graph look really bad. We can redo the previous problem as follows: > plot( x*(1-x), x = 0..1, y =0..1 ); Notice that the graph is now \true" or undistorted: the vertical and horizontal scales are the same. Multiple plots Sometimes it is useful to plot several curves at once. To plot the curves f (x) g (x) = x(1 ? x) = 4x(1 ? x) on a single graph, type: > plot({x*(1-x),4*x*(1-x)},x=0..1); Curly brackets are used in Maple to group things together. Always use regular parentheses to write algebraic formulas. Functions To get the graphs of f and g above, we typed the formulas straight into plot. A better way is to dene a function as follows: > f := x -> x*(1-x); The little thing that looks like an arrow is typed with a dash followed by a \greater than" sign (no space between them). This is supposed to represent the function as an operation, eating x and spitting out x(1 ? x). Type in > f(0.5); 4 Maple returns the correct answer of 0:25. To plot the graph of a function, type > plot(f(x),x=0..1); Try typing > plot(f,x=0..1); Doesn't look too impressive, does it? A function like f needs to know what it is operating on. Try typing > f(z); The function does its thing to whatever you put inside the parentheses. To study a family of functions, we can include a parameter, such as > F := x -> k*x*(1-x); We can give the variable (or parameter) k any value we want after dening the function. > > > > k := 1; plot(F(x),x=0..1); k := 3; plot(F(x),x=0..1); The plot changes because Maple plugged in the new value of k. If you forgot to give k a value, Maple would refuse to plot the function. To return k to its status as an undened parameter, type > k := 'k'; Make sure to use the single quote. To check the value of the parameter k, type > k; Saving and printing To save your le, go to the File menu at the top left, and click on \Save" or \Save As". Some odd-looking stu will appear. All you have to do is replace the little * in front of .mws under \Filename" with a name you can remember and hit \OK". If you want to use this le again, you can open it with the \Open" option under the File menu. Hitting \Save" now and then will spare you from losing everything in a system-wide crash. To print, go again to the File menu at the top left. Click on \print". The box for the option \Output to File" should be darkened in. In the box to the right, you can type in a name of the le (although there should already be a default name ending in \.ps"), such as assign1.ps. If you like the name, click on \Print." This saves a le in Postscript form, the language spoken by printers. To print your le, go to the local window and type the command 5 print assign1.ps and hit return. Your graph will appear on the printer, with your login name somewhere on it. Good etiquette requires taking your own printout, not someone else's. 4 Finishing up Remember to log out! Remember to change your password. Type \passwd" in your local window and follow instructions. Don't choose an obvious password. Sources of information: 1. Your instructor and the lab assistants 2. Your classmates, the person at the next workstation. Don't be afraid to ask questions. Every expert was once a beginner. 3. Handouts on the back table. Short ones are available free, longer ones are sold at cost. Among these are the \Crash Course" describes general system facilities and the Quick Tour of Maple tells more about Maple and gives further references. A nal word: In the beginning computing is frustrating because we are used to dealing with people, who are intelligent and cn undrstond whot u meen evn if it isn't quite right from a literal point of view. You will soon get past this stage as the right moves become automatic. Eventually computers will be smarter and better designed, and this will make life easier for all of us. 6 Computer Assignment I Due September 2, 2003 PROBLEMS Please staple your output graphs together, and write your name where we can nd it. Exercise 1. a. Following the instructions make and print a le that includes a graph showing both functions f (x) = x(1 ? x) and g(x) = 4x(1 ? x). Mark on the graph the point where each function takes on its maximum value, and indicate the x and y coordinates of the points. Make sure to label the axes and the functions on your graph. b. Dene the function F with parameter k as above. Plot the functions h(x) = x and F (x) = kx(1 ? x) on the same graph after setting k = 3. Estimate from the graph where the points of intersection are. Write the equation these points satisfy and nd the solutions using the solve command. Exercise 2. Find solutions of the equation cos(x2 ) ? sin(5x) ? cos(7x) = 0 by graphing G(x) = cos(x2 ) ? sin(5x) ? cos(7x) on a suitable interval and looking for where the graph crosses the x-axis for x between 1 and 2. If you see a crossing, you can get a better x on its value by graphing the function in a small interval around the crossing. State both the solution you nd and the succession of intervals you used to nd it. Describe anything interesting that went wrong. Check your answer by plugging it into the function G. What happens when you ask Maple to do nd the solution with the solve command? There is an fsolve command that nds solutions numerically (by a method we will study later in the course). Try it. Does it give a strange answer? Is it wrong? 7