------------------------------------------------------------------------- PHYS210 MAPLE 1 LAB SUMMARY Introduction to use of xmaple & maple ------------------------------------------------------------------------- ************************************************************************ 1) Open a terminal window, and within it change to your home directory, create a sub-directory called 'maple' and cd to it ************************************************************************ % cd % pwd /home/phys210d % mkdir maple % cd maple % pwd /home/phys210d/maple Also ensure that the following alias for xmaple is defined % alias xmaple alias xmaple='xmaple -cw' If you don't see the above output, get help immediately!! ************************************************************************ 2) Using xmaple to do mathematical computations interactively and saving them as a maple worksheet ************************************************************************ Let's start xmaple, and do some of the computations discussed in class, as well as some of our own. In the following, ">" denotes the xmaple prompt: you should enter only the text that follows the prompt (as we have done when entering Linux commands) From the COMMAND LINE execute % xmaple xmaple should start, and provided the xmaple window has focus, you should see a vertical-bar flashing cursor next to the ">" prompt. Try the following calculations, and NOTE THAT EVERY MAPLE STATEMENT MUST END WITH A SEMI-COLON. Observe what the output is after you execute each statement. Lines beginning with '#' below are comments, and are not to be entered. > 1 + 2; > 75 - 3; > 5*3; > 120/2; > 100! > length(%); > 1000! > length(%); > 1/2 + 1/3; > Pi; # Evaluate Pi as a floating point number using the 'evalf' # procedure. The second argument is the number of decimal # places to use > evalf(Pi, 100); > evalf(Pi, 1000); > evalf(Pi, 10000); # Maple knows about all of the standard elementary functions, as well # as many of their properties > cos(Pi); > cos( evalf(Pi, 10) ); # What's the difference between the output from the last two # statements? # Some basic operations from calculus ... diff() takes derivatives, # int() computes anti-derivatives (as well as definite integrals) > diff( cos(x) , x ); > int( x^2 , x ); #------------------------------------------------------ # BEGIN: SAVE YOUR WORK AS A MAPLE WORKSHEET #------------------------------------------------------ Use 'File -> Save As' to find the directory ~/maple, then enter first.mws in the filename box (be sure to use .mws (for "Maple WorkSheet) as the extension). Click OK. Verify that the worksheet has been created. In a terminal window execute % cd ~/maple % ls first.mws And you should see first.mws in the listing #------------------------------------------------------ # END: SAVE YOUR WORK AS A MAPLE WORKSHEET #------------------------------------------------------ # Continuing ... # Get help for any procedure or a general topic using '?' (exception # to the rule that all maple statements must end with a semi-colon) # Example ... It will take quite a bit of time for the help # facility to start up > ?cos # and you should see a help window (facility) that you can familiarize # yourself with as you work with xmaple # Use File -> Exit to quit xmaple ... Answer 'No' to the prompt # asking you whether you want to save changes # ... the GUI should disappear (including the help window) You can now restart xmaple from the command-line and load the saved worksheet. First be sure the working directory is still ~/maple, and that the worksheet is there. % cd ~/maple % pwd /home/phys210d/maple % ls first.mws Start xmaple using first.mws as the argument % xmaple first.mws And observe that the commands you previously typed interactively appear. You can now add/remove commands, and save your work by overwriting first.mws, or by creating a new worksheet. Also note that you can open a worksheet by invoking xmaple without any arguments and then using File -> Open If you wish, you can try some examples of your own later in the lab, or at your own convenience. ************************************************************************ 3) Using command-line maple to perform calculations interactively ************************************************************************ Start command-line maple from the command line in a terminal window % maple You should see something like this |\^/| Maple 16 (IBM INTEL LINUX) ._|\| |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2012 \ MAPLE / All rights reserved. Maple is a trademark of <____ ____> Waterloo Maple Inc. | Type ? for help. > Type the following commands and note the output from each > integrand := cos(x)^3 * sin(x)^2; > ans1 := int( integrand , x ); > ans2 := diff( ans1 , x ); > res1 := integrand - ans2; Note that the result is not 0 as one might expect, so try simplification. > res2 := simplify(res1); And you should see that the simplification results in 0. Quit maple ... > quit; ************************************************************************ 4) Preparing maple commands in a text file to be read into a xmaple or maple session. ************************************************************************ Within your new 'maple' directory (~/maple), and using your text-editor of choice, create and save the file 'mapletest', having contents given by the lines between the two dashed lines that follow. For the purpose of this exercise, you don't have to enter the comments---i.e. any lines that begin with '#'---in the file, so there are only 5 lines (commands) that you need to type. BE SURE THAT EACH LINE/COMMAND ENDS WITH A SEMI-COLON (;). Also note that the 5 commands are identical to those we just entered in the interactive exercise. Make sure the file is saved as 'mapletest' in the 'maple' directory. ------------------------------------------------------------------------- ####################################################### # This is a simple file containing Maple commands that # can be read into a Maple session (either the command- # line or GUI-version) ####################################################### ####################################################### # Compute a reasonably nasty indefinite integral # (anti-derivative) and assign the result to the # variable 'ans1'. Note the use of ^ for exponentiation, # and ensure that each Maple command ends with a # semi-colon, so that each command is properly # terminated and so that you will see the results # as they are executed. Also note that when computing # anti-derivatives Maple does NOT include the arbitrary # constant that typically appears; i.e. it chooses # the specific anti-derivative for which the arbitrary # constant of integration has been set to 0. ####################################################### integrand := cos(x)^3 * sin(x)^2; ans1 := int( integrand, x ); ####################################################### # Differentiate 'ans1' and assign the result to 'ans2' ####################################################### ans2 := diff( ans1, x); ####################################################### # Verify that 'ans2' and 'integrand' are equal ... You # might think that the following should evaluate # to 0 ... ####################################################### res1 := integrand - ans2; ####################################################### # ... but it doesn't! So try simplifying the last # result ... ####################################################### res2 := simplify(res1); ####################################################### # Bingo! ####################################################### ------------------------------------------------------------------------- Verify that the file containing the commands has been created, and is in the correct location % cd ~/maple % ls first.mws mapletest ************************************************************************ 5) Executing the commands in the file 'mapletest' using command-line maple ************************************************************************ Start maple (NOT xmaple) from the command line % maple Then type the following at the prompt (don't forget the semi-colon) > read mapletest; You should the following output: again, if you don't, ask for help! 3 2 integrand := cos(x) sin(x) 4 2 ans1 := -1/5 cos(x) sin(x) + 1/15 cos(x) sin(x) + 2/15 sin(x) 3 2 5 2 3 ans2 := 4/5 cos(x) sin(x) - 1/5 cos(x) - 2/15 cos(x) sin(x) + 1/15 cos(x) + 2/15 cos(x) 3 2 5 2 3 res1 := 1/5 cos(x) sin(x) + 1/5 cos(x) + 2/15 cos(x) sin(x) - 1/15 cos(x) - 2/15 cos(x) res2 := 0 Observe that the maple commands (statements) that are read from the file do not appear on the screen, only the results. Again, note how upon simplification, 'res2' evaluates to 0, verifying that the derivative of the anti-derivative is the original function, as it should be. Now exit maple ... > quit; ... and you should be returned to the command-line prompt. % ************************************************************************ 6) Executing the commands in the file 'mapletest' using xmaple, and saving them as a worksheet ************************************************************************ Remaining in your 'maple' subdirectory, invoke 'xmaple' from the command line. Make sure that the working directory is ~/maple % cd % cd maple Start xmaple % xmaple Enter the following at the prompt > read mapletest; This will again execute the commands contained in the file mapletest. Save your calculations as mapletest.mws using the procedure described above ************************************************************************ FINAL NOTE: We have seen that there are two basic ways that we can do calculations in xmaple/maple. 1) Typing expressions "interactively. 2) Preparing commands in a text file, then having maple execute them using the 'read' statement. The second approach is especially useful when writing Maple procedures (i.e. programming in Maple), since you will generally *want* the procedures/programs to be stored in text files, so that you can modify/debug your maple code easily. ************************************************************************