{VERSION 4 0 "IBM INTEL NT" "4.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "Help Heading" -1 26 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "Helvetica" 1 14 128 0 0 1 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 24 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "Helvet ica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "Helvetica" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 264 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 266 "" 0 14 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 0 14 0 0 1 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 268 "" 0 14 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 14 0 0 1 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 270 "" 0 14 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 271 "" 0 1 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 272 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 273 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 274 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 275 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 276 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 277 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 278 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 279 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 } {CSTYLE "" -1 280 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 281 "" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times " 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 } {PSTYLE "Title" -1 256 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }1 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Normal" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 10 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 258 1 {CSTYLE "" -1 -1 "T imes" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Heading 2" -1 259 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 260 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 257 37 "MLC Lab Visit - Introdu ction to Maple" }}{PARA 0 "" 0 "" {TEXT 256 27 "Mth 351 Oct 12 2001 Ma ple 6" }}{PARA 0 "" 0 "" {TEXT 258 16 "Bent E. Petersen" }{TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT 281 28 "File: 351f2001_lab_visit.mws" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 29 "This docu ment is available at" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 257 "" 0 "" {TEXT 260 41 "http://www.onid.orst.edu/~peterseb/pclab/" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 259 200 "Some of the c ommands below may not work correctly in Maple 5 and earlier (the splin e examples below, for example). Usually there are other ways to achiev e the same effect. Check Maple's built-in help." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 261 426 "If you are viewing the \+ MWS version of this document you will note all the Maple output has be en removed. You will have to execute each command (by pressing Enter w hen the cursor is on the command line) to see the output. Take the opp ortunity to experiment! Change some things. If you are viewing the PDF version, all of Maple's output will be visible, (except some of the p lots) so you can read along and make sense out of it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 358 "Click on the + sign s below to open the corresponding sections. Click on the - signs to \+ close the sections up again. The sections with blue titles are instruc tional text only. The other sections contain Maple commands. Each sect ion is independent of the other sections and each nontext section star ts with a restart command to make sure it starts fresh." }}}{SECT 1 {PARA 3 "" 0 "" {TEXT 273 12 "Introduction" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 26 0 "" }{TEXT -1 386 "Maple is a CAS, that is, a Computer Algebra System. It performs mathematical operations symbolic ally, but a large number of robust numerical routines are also built i n. Maple can be used interactively as a rather fancy calculator, but i t can also be used as a flexible programming language. Our emphasis in this introduction is on interactive use. Even so we barely scratch th e surface." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 206 "The workstations in the MLC lab are PCs running Windows NT 4.0 . You must have an ONID account or an ORST account to use the PCs in t he MLC lab. Since ORST is being phased out you should get an ONID acco unt." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 96 "W hen you logon to a machine in the MLC lab be sure the correct domain i s selected, ONID or ORST." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 254 "When you logon to a machine in the MLC lab your O NID directory on the ONID server will be visible as drive Z: This is w here you should keep your personal files. Then they will be available \+ from any PC in the MLC lab (and many other labs) when you login. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 58 "Note ther e is a lab manual (currently much out-of-date) at" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 257 "" 0 "" {TEXT 262 61 "http://www.onid.orst.e du/~peterseb/pclab/lab_enchiridion.html" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 445 "You are unlikely to need any of the information in the manual but you might want to look \+ at it for interest sake. Note in spite of what it may say in the lab m anual your user NT user profile is no longer saved (nor restored). Any thing you want to save will have to be saved explicitly on your drive \+ Z: Whatever you save on the local drive will be available only on the \+ machine you are working on, so don't save locally. Use the Z: network \+ drive." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 274 5 "Login" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 330 "The machine s in the lab are normally left on, but the monitors may be turned off. If the monitor is off, then switch it on. Next press the Ctrl-Alt-Del ete keys simultaneously. You should get a login prompt. Enter your ONI D user name and press the Tab key (not the Enter key). Then enter your ONID password and press the Enter key." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 93 "Next you may see a message about a s low network connection. This message is bogus. Ignore it." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 164 "Next you may see \+ a question about a default Novell server. Just answer \"none\" unless \+ you have a reason to answer otherwise. This question should never appe ar again." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 269 "To start Maple (or Matlab, or Mathematica, ... ) select the Start button (lower left corner of the screen), then Programs from the menu , etc. If you don't know the appropriate steps here ask for help. Writ ing all this out in detail produces an incredibly dull document." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 275 6 "Logout" }}{EXCHG {PARA 0 "" 0 "" {TEXT 263 0 "" }{TEXT -1 250 "When y ou are done with your session save your work, shutdown the software yo u were using and logout. To logout select the Start button (this is a \+ very strange Windows idiom), and then select \"Shut Down ...\" and fin ally select \"Logon as another user.\"" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 111 "Another way to logout is to press Ct rl-Alt-Delete. A menu will appear. Select logoff. That is the simplest way." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 329 "Do not select Restart or Shutdown unless you have a reason to do so a nd do not shut off the PC. There is no harm in shutting off the PC, bu t doing so causes the next user to have a long wait while the machine \+ reboots. You may turn off the monitor if you wish. That will save powe r and will reduce the load on the air-conditioner." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 186 "Note: If you do not logo ut you leave your account open for the next person to come along. That person will have access to your personal files on the ONID server. Do not forget to logout!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 549 "If you plan to leave the lab, even just for a few m inutes, save your work to the Z: drive and logoff. When you return and logon, even to a different machine, your work will be available. Do n ot select \"Lock Workstation.\" If you do, someone else wishing to use the workstation may power-cycle it in order to gain access and your u nsaved work may be lost as a result. The same comments apply to relyin g on a password protected screensaver. Don't do it. Save your work and logoff. You have no claim on any workstation if you are not physicall y present." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 " " {TEXT 276 15 "Getting Started" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 507 "Scroll down to the restart command below. Position the cursor on \+ the line containg the restart command and press Enter. Maple will exec ute the restart command and then position the cursor on the next comma nd, skipping over all the intervening text. Now press Enter to execute the next command, etc., or be brave and edit it first. Experiment! So me of the commands depend on previous assignments, etc. If you skip ar ound and something doesn't work you may just have to execute a few of \+ the previous commands." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 262 "This entire document was written in Maple. The samp le commands were selected to illustrate a few Maple features to get yo u started using Maple. To learn more you should make heavy use of the \+ online help. The help is very good and usually includes a few examples ." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 277 13 "The Worksheet" }}{EXCHG {PARA 0 "" 0 "" {TEXT 264 0 "" }{TEXT -1 470 "When you are using Maple in a window environment it is possibl e to move around on the worksheet by left-clicking the mouse. As a res ult, commands may end up being executed in a nonlinear order. This can cause some confusion, since there is no visual clue. One way to fix a mess is to have Maple re-execute the whole worksheet (look on the Edi t menu). This works best if old expressions are cleaned up first, so i t is a good idea to start each worksheet with the command " }{TEXT 265 8 " restart" }{TEXT -1 42 " . You do not need to do so of course . ..." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 266 132 " Maple commands are executed by pressing the Enter key when the mouse c ursor (pointer, thumb) is in the line containing the commands." } {TEXT 267 76 " Note that Maple skips over the interpolated text commen ts (like this one). " }{TEXT 268 139 "To execute the commands on this \+ worksheet position the mouse cursor on the command line and press Ente r. Edit the command first if you wish" }{TEXT 270 1 "." }{TEXT 269 72 " Explore! Simply waiting for something to happen will not be producti ve." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 239 "N ote each Maple command must be terminated by a colon or a semicolon (e xcept help commands preceded by a question mark). The effect of the co lon is to suppress output from the corresponding command, though the c ommand is still carried out." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 347 "You can spread the command over several lines \+ by postponing the terminating colon or semicolon. You simply move to a new line by pressing Enter. Maple will chatter at you when you move t o a new line in this manner if the previous command is unterminated. I gnore it, but keep in mind a command will not be executed before it is properly terminated." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 220 "You can also stack up several commands on one line by terminating them individually with colons or semicolons. All the com mands on a line are executed when you press the Enter key (with the cu rsor anywhere on the line)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 222 "Here's a useful fact: You can open a new comma nd line below the current one by pressing Ctrl-J, or above the current line, by pressing Ctrl-K. This is pretty useful when you realize you \+ omitted something at a certain step." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 30 "Assignment and Ditto Operator s" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 129 "The assignment operator in maple is := (colon and equals sign juxtaposed). The equals sign by itself does no t perform assignment." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 248 "Maple has two ditto operators, % and %%. The value of % is the previously evaluated expression, the value of %% is the \+ one before that. Since the Worksheet commands may be executed in any o rder, the ditto operators can cause a lot of confusion." }{TEXT 272 1 " " }{TEXT 271 87 "It is probably best to restrict them to the same li ne as the expressions they refer to." }{TEXT -1 74 " Here is a silly e xample, which also demonstrates the assignment operator." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "a:=5 ; b:=4; %%; %%; %;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 137 "You can also unassign variables. Right now a i s 5. That would cause problems if we want to use a as a dummy varia ble of integration!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "unassign('a','b'); a; b;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 63 "You can p ass any number of variables to the unassign() command." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 114 "A simpler way to un assign one variable is to assign it its name extracted by single quote s (this is a Maple idiom)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "a:=5; a:='a': a;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 279 "This is quite convenient, but som etimes the single quotes are hard to find on the keyboard and even har der to see on the monitor. Thus, even though it is more typing you may prefer to use the evaluate to a name function evaln() since it does \+ not require the pesky single quotes." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "a:=5; b:=4;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "unassign(evaln(a),evaln(b)); a; b; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 92 "Unfortunately, you can pass only one expression to evaln(), since \+ it returns only one name. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 175 "Some Maple statements may have equal signs in th em. It is important to remember that the the equals sign by itself (wi thout a preceeding colon) does not perform an assignment." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "3=4; 3:=4;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 222 "Here the error comes from trying to assign 4 to 3. The e xpression 3=4 causes no problem though. It is simply an expression. Th e truth value of an expression may be evaluated by using the evaluate \+ Boolean, evalb(), function" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "evalb(3=4); evalb(3=3);" }{TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 9 "Constants" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "rest art;" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 28 "Maple has built-in cons tants" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "Pi = evalf(Pi,60); I; I^2; gamma = evalf(gamma,40); \+ " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 108 "Note the upper case letters. If you enter pi you will just get th e Greek letter pi, not the real number pi. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 357 "The evalf() function evaluates an expression to floating point. As you can see, the evalf() function takes a second parameter specifiying the precision in decimal digits. This parameter is optional. If it is not specified then the global co nstant Digits is used (the default value is 10, but you can assign any positive integer value (up to many thousands)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "evalf(Pi); \+ " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "evalf(Pi,200);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 118 "N ote the use of the line continuation character \\ in Maple's response \+ when the response will not fit on a single line." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 6 "Digits" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 238 "You set the Maple's floating point precision by a ssigning a value to Digits (the default is 10). Maple usually does exa ct calculations, but when floating point numbers are involved then Dig its sets the precision. Here's an amusing example" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "Digits:=4: \+ convert(evalf(Pi),rational);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 172 "The conversion to a rational number ma kes use of Digits, rather than any precision specified in the evalf() \+ command. You can easily find other rational approximations to pi" } {MPLTEXT 1 0 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "Digits:=8: convert(evalf(Pi),rational);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 103 "The label \"rational\" is protect ed in Maple 6. You can not assign a value to it (which is just as well )." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "Functions and Expressions" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 91 "Maple distingu ishes between functions and expressions. Here's one way to define a fu nction:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "f:=x->sin(3*x+x^2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 40 "We can also define a related ex pression:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 16 "g:=sin(3*x+x^2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 261 "Both of the examples above ass ume that x has not already been assigned a value. It needs to be an \+ unassigned variable. In the definition of f the x is a dummy varia ble, a place marker. In g however, it is part of the expression, and one can refer to it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 159 "To evaluate a function we use the usual function conv ention. To evaluate an expression one generally uses the subs() comman d (though it has other subtle uses)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "f(1); subs(x=1,g);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 59 "No te the subs() command above does not assign a value to x." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 310 "An expression can also be evaluated by using the eval() command, but do check help to m ake sure you don't have any surprises in more complicated situations. \+ The commands eval() and subs() work in quite different ways. In the si mple case that we illustrated here eval() is actually the preferred co mmand to use." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "eval(g,x=1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 60 "Note the eval() command above d oes not assign a value to x. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 75 "We can convert an expression into a funct ion by using the unapply() command" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "h:=unapply(g,x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 226 "Y ou can think of unapply() as turning the indicated variable(s) into du mmy variables or place markers. Thus f(x) is the the function f ev aluated at x and unapply(f(x),x) ought to return the function f. Le t's check that:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 31 "ff:=unapply(f(x),x); (ff-f)(w);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "Sure enou gh!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 150 "I f you have an inquisitive nature you probably wonder if Maple has an a pply() command. It does but the functional notation is usually more co nvenient." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 22 "is(f(t) = apply(f,t));" }}}}{SECT 1 {PARA 3 "" 0 " " {TEXT -1 11 "Derivatives" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 83 "Some Maple commands work on expressions, some work on fun ctions, and some on both. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "f:=x->exp(3*x^2)*cos(4*x); g:=exp(3 *x^2)*cos(4*x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "D(f); di ff(g,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 198 "Here D is the operator for differentiating a function, whereas diff() is used for an expression. Note in diff() you have to specify the variable that you wish to differentiate with respect t o." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 33 "Second derivatives are no problem" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "D(D(f)); diff(g,x,x) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 124 "but this notation can get out hand. Fortunately there is an alter native! Here are the fourth derivatives as an illustration:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "( D@@4)(f); diff(g,x$4);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 119 "Partial derivatives of expressions are a lso easily computed (here once relative to y and three times relativ e to x):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 24 "diff(x/(x^2+y^2),x$3,y);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 415 "There is an inert version Diff() of diff(). An inert fun ction returns unevaluated. That may seem strange, but sometimes one ca n save time by postponing evaluation, or one can prevent Maple from at tempting a calculation that will fail at present, but can be carried o ut later in special cases or different contexts. Unevaluated expressio ns may be evaluated by using the command value(), thought there are ot her ways." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "Inert functions, together with the ditto operator can be used to \+ get nicely typeset expressions. See if you can sort out the following: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "Diff(x/(x^2+y^2),x$3,y): %=value(%);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 11 "Integration" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 263 "Let' s bring back some fond memories from calculus - the problem of integra tion. Here's an example to get you started: Once again I use postponed evaluation to get a nicely typeset equation. You don't need to do suc h trickery, of course, but it's nice to know how." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "Int(1/(1+x^ 4),x): % = value(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 41 "You can obtain the same effect by writing " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "Int(1/(1+x^4),x) = int(1/(1+x^4),x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 142 "if you d on't mind writing the integrand twice. In both these example the equal s sign is just part of the expression. It is not an assignment. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 110 "If you a re just interested in evaluating the integral then you can dispense wi th all the typesetting niceties:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "int(1/(1+x^4),x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 168 "N ote that int() function works on expressions, not functions. Thus to i ntegrate a function you have to convert it to an expression by evaluat ing it at a dummy variable." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "h:=t->t^3; int(h(u),u);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 72 "I \+ bet you wish you had a tool like this when you were studying calculus! " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 46 "Natur ally definite integrals are possible too." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "Int(2*x^2*log(x)^3+x ^3*log(x),x=1..2): %=value(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 138 "If you want a floating point number \+ you can simply use evalf(), but there is a subtle and important differ ence depending on how you do it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 54 "a:=int(2*x^2*log(x)^3+x^3*lo g(x),x=1..2): evalf(a,16);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "evalf(Int(2*x^2*log(x)^3+x^3*log(x),x=1..2),16);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 299 "In the first c ase we assign the symbolic expression for the integral to a and then evaluate that expression. In the second example, Maple detects that w e want a numeric result and evaluates the integral numerically without first trying to obtain a symbolic solution. This is important. For ex ample" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "st:=time():" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "int(arctan( x)/log(x),x=Pi/8..Pi/4); evalf(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "TIME = time() - st;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "st:=time():" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "evalf(Int(a rctan(x)/log(x),x=Pi/8..Pi/4));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "TIME = time() - st;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 500 "Here, in the first case, Maple decided \+ after a while (possibly a long while) that it can not return a symboli c value for the integral and so returned it unevaluated. Then evalf() \+ called a numeric quadrature rule to get an answer. In the second case \+ however, Maple wasted no time trying to find a nonexistent symbolic so lution, but instead used a numeric quadrature method. This is an impor tant use of inert functions. You can grow noticably older waiting for \+ a symbolic solution to a complex problem." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 137 "There are refinements. For exampl e, you can specify what quadrature method to use. Enter the command ?i nt[numeric] for more information." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "Some Plots" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart; " }}}{EXCHG {PARA 260 "" 0 "" {TEXT 280 124 "Functions and expressions can be plotted. There are numerous plot variations. Check the help f acility, ?plot, for details." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "f:=x->sin(1/x); g:=sin(1/x); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "plot(g,x=0..1,numpoints =200,title=\"Plotting an expression\"):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "plot(f,0..1,numpoints=200,title=\"Plotting a function \");" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 75 "Replace the colon above by semicolons and press Enter to genera te the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 88 "We can convert a function into an expression simply by evaluati ng it, so one can also do" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 " plot(f(x),x=0..1):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 76 "Replace t he colon above by a semicolon and press Enter to generate the plot." } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 117 "You can also plot anonymous functions, or expressions, that is, plot them wit hout first assigning them to a variable:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "plot(x->x+sin(x),0.. 4*Pi);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "plot(x+sin(x),x=0 ..4*Pi):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 75 "Replace the colon above by semicolons and press Enter to \+ generate the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 171 "Maple has many plot types. Some 3D plots are demonstrate d below, but if you need something else, you will have to explore Mapl e help to see if you can find what you want.." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "More Plots" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 152 "Maple has a number of built-in plot commands. Additional commands are made available by loading the plots package (by means of the with(plots) command)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "Here is a well-know plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "plot3d(sin( sqrt(x^2+y^2))/sqrt(x^2+y^2),x=-7..7,y=-7..7);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 202 "We can also do para metric plots. We will use parameters t and p, so lets make sure fi rst they have not been assigned to some other expressions (otherwise w e will get incomprehensibe error messages)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "t:=evaln(t): p:=e valn(p):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 73 "plot3d([4*cos(t )*sin(p),4*sin(t)*sin(p),4*cos(p)],t=-Pi..Pi/2,p=0..Pi/2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 101 "Many oth er plot commands are available. Check ?plots. A nice plot to experime nt with is the tubeplot" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 58 "tubeplot([t,t^2,t*sin(t)],t=-1..22,radius=6*(2 +cos(t/4)));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 95 "Note you can drag the plot around with the mouse to see the surface from different view points." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "tubeplot([4*cos(t),4 *sin(t),4*t],t=0..18,radius=1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "tubeplot([2*cos(t),2*sin(t),1],t=0..2*Pi-1/2,radius=1,numpoint s=60);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 36 "Taylor Series and Tay lor Polynomials" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 0 "" }{TEXT 278 0 "" }{TEXT -1 274 "Maple can compute Taylor and interpolation polynomials. Actually \+ the Taylor polynomial is a special case of an interpolation polynomial , with all the nodes equal. but Maple's interpolation routine requires distinct nodes (we can get around that restriction by using limits). " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 50 "Let's start with an example of Taylor polynomials:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "tay1:=taylo r(exp(2*sin(x)),x=0,10);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 166 "Note taylor() works on expressions. The \+ second argument specifies the center. The third argument specifies the order of the terms omitted. Parameters may be included:" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "a:=e valn(a);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "tay2:=taylor(ex p(a*sin(x)),x=0,5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 175 "Note I unevaluated a first, because we left i t assigned to some number above. If I had not unevaluated it then Mapl e would have substituted the value of a in this expression." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 132 "The data type \+ returned by taylor() is a series, not a polynomial. If you want a poly nomial to play with you need to do a conversion:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "taylor(tan( x),x=0,10): p:=convert(%,polynom);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 127 "In Maple 6 polynom is a reserv ed name (for a data type) so you do not have to worry that you might h ave assigned a value to it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "You can specify a different center, even a symb olic one" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "c:=evaln(c):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "taylor(exp(x),x=c,4): pc:=convert(%,polynom);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "Interpolation Polynomials" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "Maple provides a built-in command for computing interpola tion polynomials. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "q1:=interp([1,3,4,2],[2,1,3,1],x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 193 "T he first parameter we pass to interp() is the list of (distinct) absci ssas, the second is the list of ordinates and the third is a name, the name for the variable to be used in the polynomial." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 110 "If you want a polynomi al function rather than a polynomial expression in some variable, you \+ can use unapply():" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "q2:=unapply(interp([1,3,4,2],[2,1,3,1],x),x );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 27 "Let's check that it worked:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "q2(1); q2(3); q2(4); q2(2); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 163 "If you have a list of points you want to interpolate you can extr act the abscissas and ordinates by using the op() command (it lists th e operands in its argument):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "L:=[ [1,2], [2,-1], [3,-2], \+ [-1,1], [-2,7], [8,6], [7,5] ];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 108 "We start by declaring two empty lis ts, XX and YY, and then push the abscissas on XX and the ordinates on \+ YY:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 77 "XX:=[]: YY:=[]: for pnt in L do XX:=[op(XX),pnt[1]]; \+ YY:=[op(YY),pnt[2]]; od:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 252 "Here pnt is a list with two entries (i t represents one of our points) , pnt[1] is the first entry in pnt ( think the x coordinate), and pnt[2] is the second entry (think the y \+ coordinate). Before we use XX and YY let's check that they look alrig ht" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "XX; YY;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 " p3:=interp(XX,YY,x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "plo t(p3,x=1..7,title=\"p3\");" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 186 "A convenient way to construct an interpo lation polynomial for a function is to use the map() command to evalua te the function at each abscissa. Let's consider the sine function on \+ [0,4]:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "XX:=[0,1/2,1,3/2,2,5/2,3,7/2,4];" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 23 "YY:=evalf(map(sin,XX));" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 126 "Here we used eval f() to force (approximate) evaluation of the sine. Otherwise we will g et an (painfully) exact answer. Try it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "ps:=interp(XX,YY,t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 89 "plot([ps,sin(t)],t=0..6.5 ,title=\"Interpolation (red) of sin(t) (blue)\",color=[red,blue]);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 79 "N ote the previous example shows one way of plotting two functions on on e graph." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 21 "Interpolation Splin es" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 279 0 "" }{TEXT -1 267 "Maple com putes splines of all degrees - check the help. Here we will look only \+ at linear and (natural) cubic splines. A linear spline is just a piece wise linear function. The parameters are much the same as for interp() , but the abscissas must be in increasing order." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "XX:=[1,2,5/ 2,3,13/4,15/4,5];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "YY:=[1 ,1,2,1,-1,-1,3];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "sp1:=sp line(XX,YY,x,linear);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "sp 3:=spline(XX,YY,x,cubic);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 135 "plot([sp1,sp3],x=1..5,color=[red,blue],thickness=2,numpoints=200, title=\"piecewise linear (red) and cubic spline (blue) interpolation\" );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 230 "You can see how the cubic spline smoothens out the graph witho ut introducing too much oscillation. If we compare the piecewise linea r spline and the interpolation polynomial we see unreasonable oscillat ion unsupported by the data:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "pp:=interp(XX,YY,x);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 132 "plot([sp1,pp],x=1..5,color= [red,blue],thickness=2,numpoints=200,title=\"piecewise linear (red) an d polynomial interpolation (blue)\"):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 76 "Replace the colon above b y a semicolon and press Enter to generate the plot." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 203 "Note the vertical scal es are different in the two graphs. We can plot all three function in \+ one graph for a more convincing demonstration of how well the cubic sp line follows the piecewise interpolation." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 161 "plot([sp1,sp3,pp],x =1..5,-3..9,color=[red,blue,black],thickness=2,numpoints=200,title=\"r ed=piecewise linear, blue=cubic spline, black=interpolation polynomial \"):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 76 "Replace the colon above by a semicolon and press Enter to gener ate the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 174 "Note how I restricted the vertical range to -3..9 so we would be able to see the details (otherwise the piecewise linear and \+ the cubic spline just about merge on the graph)." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 31 "Trapezoidal and Simpson's Rules" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 229 "Maple has numerous high-power quadrature methods built in, but if one simply wants to experiment with the trapezoidal rule or Simpso n's rule, these are available in the student package, accessed through the command with(student)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 179 "It is also fairly easy to roll your own, even \+ to write high order Newton-Cotes methods, if you wish. There are some \+ example on my web page. For now, let's use the student package." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "with(student): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "tr apezoid(f(x),x=a..b,6);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 " simpson(f(x),x=a..b,6);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 173 "The first command above loads the studen t package. This package contains the code for the trapezoidal, Simpson 's rule and many other things. It is a standard part of Maple. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 48 "Let's try an actual function, say exp(x)*cos(x)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "trapezoid(exp(x)*cos(x ),x=0..3,12): test:=evalf(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "simpson(exp(x)*cos(x),x=0..3,12): sest:=evalf(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "int(exp(x)*cos(x),x=0..3); evalf(%) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 57 "As we expected, Simpson's rule performs much better here." }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 17 "Sums and Products" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Maple can compute quite a few standard sums and products: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "expr:=k^2,k=1..n: Sum(expr)=sum(expr); expand(%);" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "Sum(k^3,k=1..n): %=value(%) ; expand(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "Sum(k^4,k=1 ..n) = sum(k^4,k=1..n); expand(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 248 "These three examples illustrat e different ways of achieving the same typographical effect. Note that sum() computes a sum, whereas Sum() simply returns unevaluated. The f irst example also shows that you can assign any kind of expression to \+ a label." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "Here's an obvious product" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "product(k/(k+1),k=1..n); sim plify(%);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 13 "Number Theory" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 167 "Maple has a some simple number theory support bui lt-in. Additional resources are available in the (standard) numtheory \+ library (loaded by with(numtheory) if needed)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 128 "We can compute greatest \+ common divisors, gcd, and least common multiples, lcm, of polynomials, and so in particular of integers." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "gcd(810,35);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "lcm(810,35);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "We can test for prim ality" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "isprime(7531829);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "isprime(1337);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 22 "We can factor integers" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ifac tor(1337);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "ifactor(11111 11111111111111111111111111111111111);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 82 "We can compute Mersenne p rimes, that is primes of the form 2^n-1 (n must be prime)" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "with (numtheory):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "for k from \+ 1 to 11 do 'k'=k, mersenne(k); od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 117 "If you just want to list known Mersenne primes (Maple has a built-in list) you can use a modified me rsenne() command:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 40 "for k from 1 to 11 do mersenne([k]); od;" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 105 " If you want to find the k's which gives rise to the Mersenne primes above, you could do the following:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 93 "for k from 1 to 11 do 2^n- 1 = mersenne([k]), 'n' = round(evalf(log[2](mersenne([k])+1))); od;" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 39 " There's probably a better way to do it!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 165 "The Mersenne primes grow pretty qui ckly. When you get to thousands of digits perhaps you are satisfied ju st knowing how many digits without seeing the actual number." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 100 " for k from 25 to 31 do \"digits in k-th mersenne prime\", 'k'=k, 'digi ts' = length(mersenne([k])); od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 331 "A positive integer is a perfect \+ number if it is the sum of its proper divisors. Euclid showed that an even number M is perfect if and only if M is of the form M = 2^ (q-1) (2^q-1) where 2^q-1 is prime (so a Mersenne prime). No one kn ows if there are any odd perfect numbers. Here's a list of the first f ew perfect numbers" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 87 "for k from 1 to 12 do n:=mersenne([k])*2^ (round(evalf(log[2](mersenne([k])+1)))-1); od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 44 "The first 4 have bee n known since antiquity." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Here is the Euler polynomial that produce s so many primes" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "p:=x->x^2+x+41;" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "for k from 1 to 40 do; k, if actor(p(k)), isprime(p(k)); od;" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 17 "Solving Equations" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "rest art;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 161 "We can solve a few equat ions symbolically with solve(), and many more numerically with fsolve( ). Note we can specify the range in which to look for a solution. " } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "fsolve(tan(x)=3*x,x,avoid=\{x=0\},0..1.4);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 127 "We didn't actuall y need the avoid=\{x=0\} here, but it is one way to make sure the tri vial solution x=0, is not the one found." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "fsolve(tan(x)=3*x ,x,1.4..5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "solve(x^4+1= 0,x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "solve(sin(x)=cos(x ),x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 30 "We can also solve some systems" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "solve(\{x+2*y=3,3 *x-2*y=5\},\{x,y\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 96 "For serious work with linear equations use the \+ linear algebra packages, linalg or LinearAlgebra." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 6 "Limits" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 43 "Maple has a limite d understanding of limits" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "limit((exp(x)-1-x)/x^2,x=0);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 100 "A s above, we can use the inert (unevaluated) form of limit(), i.e., Lim it(), to do fancy typography." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 58 "Limit((exp(x)-1-x)/x^2,x=0) \+ = limit((exp(x)-1-x)/x^2,x=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 48 "Or with less typing (and less chance \+ for errors)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "Limit((exp(x)-1-x)/x^2,x=0): % = value(%);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "He re are some more limits" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "k:=evaln(k): Sum(k^(-4),k=1..infini ty): %=value(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "sum(1/k ^1.0002,k=1..infinity);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 " Int(exp(-x^4),x=0..infinity): %=value(%);" }}}}{SECT 1 {PARA 3 "" 0 " " {TEXT -1 22 "Recursion and remember" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "We ca n define sequences and functions recursively" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "T := n->" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "if n=1 then 3;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "elif n=2 then 1;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "else 2*T(n-2)+T(n-1);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "fi:" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 41 "a nd then compute any part of the sequence" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "L:=[]: for k from 11 to 15 do L:=[op(L),T(k)]: od: L;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 158 "Note here op(L) returns the ope rands in L, then we tack on T(k) and form a list by enclosing everyth ing in square brackets, i.e., we push T(k) on the list." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 264 "This calculation is actually very inefficient. If we write it as a procedure with the rem ember option, then Maple will remember results from previous incantati ons of the procedure (there are many since it calls itself) and theref ore run quicker (but use more RAM)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "TT:=proc(n)" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 16 "option remember;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "if n=1 then 3;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 " elif n=2 then 1;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "else 2*TT(n-2)+ TT(n-1);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "fi:" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 39 "Let's check the run-times (in seconds)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "tm:=time(): T(25); time()-tm;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "tm:=time(): TT(25); time()-tm;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 249 "Your times will dif fer from mine, but you will see that TT is hundreds of times faster \+ than T. Keep the \"option remember\" in mind when doing recursion. If you try to compute T(1000) you will grow very much older, whereas TT (1000) is very quick." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "tm:=time(): TT(2000); time()-tm;" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 196 "If you try to compute TT(n) for too large an n Maple will return \+ an error, \"Too many levels of recursion.\" It is not always a good id ea to define a function recursively, even when it is slick." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "Set T heory" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "Maple has a few set theory commands built in. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "U:=\{1,2,3,4,5,6,7,8,9,10,11,12\}; # small universe" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "A:=\{3,5,7,9\}; B:=\{2,3, 5,6,7\}; C:=\{2,4,6,8\};" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A union B;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "B intersect \+ C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "B minus A;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A minus B;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 87 "We can define o ur own absolute complement function (relative to our selected universe ):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "complement:=X->U minus X;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 14 "complement(A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "complement(B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "complement(C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "( A union B) minus C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 54 "comp lement(A union B) intersect complement(B union C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "(A union C) minus (C minus A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 122 "The symm etric difference measures by how much two sets differ. We can easily d efine our own symmetric difference function." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 46 "symdiff:=(X,Y)->( X minus Y) union (Y minus X);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "symdiff(A,B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "symd iff(A,C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "symdiff(B,C); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 29 "We can easily test membership" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(3,A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(4,A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 179 "Here's a simple way to define a procedure carp() to compute the Cartesian product. This i s a bit more complicated than the arrow notation for functions, but is much more flexible." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "carp:=proc(X,Y)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 " local Z,x,y;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 8 " \+ Z:=\{\};" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 " for x in X do" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 " for y in Y do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " Z:=Z union \{[x,y]\};" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 7 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "return Z;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "car p(A,A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "carp(A,B);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "carp(A,C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "carp(A,B) minus carp(A,C);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 38 "We can de vise our own test for subsets" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "subset:=proc(X,Y)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 12 " local x,s;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 10 " s:=true;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 " fo r x in X do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 26 " s:= s and member (x,Y);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "s ubset(A,B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "subset(\{9,5 \},A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 126 "Here's a slicker way to check for a subset. Here evalb() means evaluate Boolean, that is, find the truth value of a statement. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "subset2:=(X,Y)->evalb((X minus Y)=\{\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "subset2(A,B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "subset2(\{9,5\},A);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 370 "The power set may be c omputed by using the Maple function choose() from the the combinat pa ckage. To use it we have either to load the combinat package by issuin g the command with(combinat) or we have to call the function by using \+ its so called long name combinat[choose](). We will use the second met hod but we will rename the function to the more convenient powset()." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "alias(powset=combinat[choose]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "powset(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 121 "Try to be reasonable. If you decide to \+ compute powset(carp(A,B)) you will have a long wait. This set has 2^ 20 elements!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "2^20;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 53 "It will take a while to list over 1 milli on elements." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 144 "We have barely scratc hed the surface of Maple. There are many other things Maple can do. Tr y exploring the help facility. Above all, experiment!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{MARK "0 7 0" 1 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }