{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 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 264 "" 0 14 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 265 "" 0 14 0 0 1 1 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 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 1 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 270 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 271 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 272 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 0 }{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 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 277 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 278 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 279 "" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 0 }{PSTYLE "Norma l" -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 "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 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 }{PSTYLE "Normal" -1 261 1 {CSTYLE "" -1 -1 "Times" 1 12 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 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 257 37 "MLC Lab Visit - Introdu ction to Maple" }}{PARA 0 "" 0 "" {TEXT 256 28 "Mth 351 July 11 2002 M aple 6" }}{PARA 0 "" 0 "" {TEXT 258 16 "Bent E. Petersen" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 279 28 "File: 351u2002_lab_visit.mws" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 259 217 "I use M aple 6 at present though I may upgrade to Maple 7 soon (though apparen tly 8 is out). Some of the commands below may not work correctly in Ma ple 5 and earlier, and some may not work correctly in Maple 7 or later " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 260 380 "If \+ you are viewing the MWS version of this document you will note all the Maple output has been removed. You will have to execute each command \+ (by pressing Enter when the cursor is on the command line) to see the \+ output. Take the opportunity to experiment! Change some things. If you are viewing the PDF version, most of Maple's output will be visible, \+ though I may suppress some." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 358 "Click on the + signs below to open the corre sponding sections. Click on the - signs to close the sections up aga in. The sections with blue titles are instructional text only. The oth er sections contain Maple commands. Each section is independent of the other sections and each nontext section starts with a restart comma nd to make sure it starts fresh." }}}{SECT 1 {PARA 3 "" 0 "" {TEXT 271 12 "Introduction" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 26 0 "" }{TEXT -1 386 "Maple is a CAS, that is, a Computer Algebra Sys tem. It performs mathematical operations symbolically, but a large num ber of robust numerical routines are also built in. Maple can be used \+ interactively as a rather fancy calculator, but it can also be used as a flexible programming language. Our emphasis in this introduction is on interactive use. Even so we barely scratch the surface." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 214 "One feature of Maple that may interest some of you is the possibility of executing M atlab commands from within Maple. In Maple 6 this feature requires tha t you have Matlab 5 or later installed on the same computer." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 126 "The workstatio ns in the MLC lab are PCs running Windows NT 4.0. You must have an ONI D account to use the PCs in the MLC lab. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 89 "When you logon to a machine in \+ the MLC lab be sure the correct domain is selected - ONID." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 254 "When you logon t o a machine in the MLC lab your ONID directory on the ONID server will be visible as drive Z: This is where you should keep your personal fi les. 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 there is a lab manual (currently much out- of-date) at" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 261 "" 0 "" {TEXT -1 61 "http://www.onid.orst.edu/~peterseb/pclab/lab_enchiridion. html" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 478 " 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 m ay say in the lab manual your user NT user profile is no longer saved \+ (nor restored). Anything you want to save will have to be saved explic itly on your drive Z: Whatever you save on the local drive will be ava ilable only on the machine you are working on, and may be deleted peri odically, so don't save locally. Use the Z: network drive." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 272 5 "Login" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 330 "The machines in the lab are nor mally left on, but the monitors may be turned off. If the monitor is o ff, then switch it on. Next press the Ctrl-Alt-Delete keys simultaneou sly. You should get a login prompt. Enter your ONID user name and pres s the Tab key (not the Enter key). Then enter your ONID password and p ress the Enter key." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 93 "Next you may see a message about a slow network connect ion. This message is bogus. Ignore it." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 123 "Next you may see a question about a \+ default Novell server. Just answer \"none\" unless you have a reason t o answer otherwise." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 269 "To start Maple (or Matlab, or Mathematica, ... ) selec t the Start button (lower left corner of the screen), then Programs fr om the menu, etc. If you don't know the appropriate steps here ask for help. Writing all this out in detail produces an incredibly dull docu ment." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 273 6 "Logout" }}{EXCHG {PARA 0 "" 0 "" {TEXT 261 0 "" }{TEXT -1 250 "When you are done with your session save your work, shutdown t he software you were using and logout. To logout select the Start butt on (this is a very strange Windows idiom), and then select \"Shut Down ...\" and finally select \"Logon as another user.\"" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 111 "Another way to logout \+ is to press Ctrl-Alt-Delete. A menu will appear. Select logoff. That i s 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 re ason to do so and do not shut off the PC. There is no harm in shutting off the PC, but doing so causes the next user to have a long wait whi le the machine reboots. You may turn off the monitor if you wish. That will save power 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 logout 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 j ust for a few minutes, 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 not select \"Lock Workstation.\" If you do, someone else wishing to use the workstation may power-cycle it in order to gain ac cess and your unsaved work may be lost as a result. The same comments \+ apply to relying on a password protected screensaver. Don't do it. Sav e your work and logoff. You have no claim on any workstation if you ar e not physically present." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT 274 15 "Getting Started" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 552 "Scroll down to the restart command below (in the se ction, Assignment and Ditto Operators). Position the cursor on the lin e containg the restart command and press Enter. Maple will execute the restart command and then move the cursor on the next command, skippin g over all the intervening text. Now press Enter to execute the next c ommand, etc., or be brave and edit it first. Experiment! Some of the c ommands depend on previous assignments, etc. If you skip around and so mething doesn't work you may just have to execute a few of the previou s commands." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 262 "This entire document was written in Maple. The sample commands were selected to illustrate a few Maple features to get you started u sing 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 275 13 "The \+ Worksheet" }}{EXCHG {PARA 0 "" 0 "" {TEXT 262 0 "" }{TEXT -1 470 "When you are using Maple in a window environment it is possible to move ar ound on the worksheet by left-clicking the mouse. As a result, command s 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 Edit menu). Thi s works best if old expressions are cleaned up first, so it is a good \+ idea to start each worksheet with the command " }{TEXT 263 8 " restart " }{TEXT -1 42 " . You do not need to do so of course ...." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 264 132 "Maple commands \+ are executed by pressing the Enter key when the mouse cursor (pointer, thumb) is in the line containing the commands." }{TEXT 265 76 " Note \+ that Maple skips over the interpolated text comments (like this one). \+ " }{TEXT 266 139 "To execute the commands on this worksheet position t he mouse cursor on the command line and press Enter. Edit the command \+ first if you wish" }{TEXT 268 1 "." }{TEXT 267 72 " Explore! Simply wa iting for something to happen will not be productive." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 140 "Note some of the comm ands on this worksheet depend on previous commands. For best results y ou should probably execute the commands in order." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 335 "Note each Maple command \+ must be terminated by a colon or a semicolon (except help commands pre ceded by a question mark). The effect of the colon is to suppress outp ut from the corresponding command, though the command is still carried out. If you normally use Matlab you may experience some difficulties \+ with the colons and semicolons!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 411 "You can spread the command over several \+ lines by postponing the terminating colon or semicolon. You simply mov e to a new line by pressing Enter. There is no visible line continuati on character (as in Matlab). 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 0 "" 0 "" {TEXT -1 0 "" }}{PARA 259 "" 0 "" {TEXT -1 129 "The as signment operator in maple is := (colon and equals sign juxtaposed). T he equals sign by itself does not perform assignment." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 142 "Note once you have as signed a value to a variable you can display the value by entering (pr operly terminated) the variable name at the prompt." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "var:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "var;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 117 "You can retrieve \+ the name of a variable by enclosing it in single quotes. This is handy for producing equations. Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "'var' = var;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "'log(3.72)' = log(3.72);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 248 "M aple has two ditto operators, % and %%. The value of % is the previo usly evaluated expression, the value of %% is the one before that. S ince the Worksheet commands may be executed in any order, the ditto op erators can cause a lot of confusion." }{TEXT 270 1 " " }{TEXT 269 87 "It is probably best to restrict them to the same line as the expressi ons they refer to." }{TEXT -1 81 " Here is an example which also illus trates the quoting mechanism discussed above:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "''log(3.72) '': % = value(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 193 "Note we had to quote twice because the outer set \+ of quotes is stripped off during an assignment and here there is an im plicit assignment to %. Try using just single quotes to see what happ ens." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 137 "You can also unassign variables. Right now a is 5. That wou ld cause problems if we want to use a as a dummy variable of integra tion!" }}{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 pass any number o f variables to the unassign() command." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 111 "A simpler way to unassign one variab le is to assign it its name quoted by single quotes (this is a Maple i diom)" }}{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 sometimes the single quote s are hard to find on the keyboard and even harder to see on the monit or. Thus, even though it is more typing you may prefer to use the eval uate to a name function evaln() since it does not require the pesky s ingle 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 them. It is importa nt to remember that the the equals sign by itself (without a preceedin g 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 223 "H ere the error comes from trying to assign 4 to 3. The expression 3=4 c auses no problem though. It is simply an expression. The truth value o f 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 "C onstants" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}} {EXCHG {PARA 259 "" 0 "" {TEXT -1 28 "Maple has built-in constants" }} {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 114 "Note the upper case letter for Pi. If you enter pi you will just get the 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 expr ession to floating point. As you can see, the evalf() function takes a second parameter specifiying the precision in decimal digits. This pa rameter is optional. If it is not specified then the global constant D igits is used (the default value is 10, but you can assign any positiv e 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 "Note the use of the line continuation character \\ in Maple's response when th e 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 assigning a va lue to Digits (the default is 10). Maple usually does exact calculatio ns, but when floating point numbers are involved then Digits 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 makes use of Di gits, 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 protected in M aple 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 distinguishes \+ between functions and expressions. Here's one way to define a function :" }}{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 36 "Here $ is the sequence command. Thus" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "y$10;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 92 "The @@ command is a composition command. It can be appl ied to other functions or operators" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "g:=x->c*x*(1-x); (g@@2)(x) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 4 "Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "solve((g@@2)(x)=x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 41 "gives us the points of period \+ 2 for g." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 119 "Partial derivatives of e xpressions are also easily computed (here once relative to y and thr ee times relative 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 555 "There is an inert version Diff() of dif f(). An inert function returns unevaluated. That may seem strange, but sometimes one can save time by postponing evaluation, or one can prev ent Maple from attempting a calculation that will fail at present, but can be carried out later in special cases or different contexts. The \+ most important use of unevaluated commands is to prevent an attempt at a symbolic solution when that is impossible or very complicated. Unev aluated expressions may be evaluated by using the command value(), tho ught there are other ways." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "Inert functions, together with the ditto operato r can be used to get nicely typeset expressions. See if you can sort o ut 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 o f integration. 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 such 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 41 "You can obtain the same effect by writi ng" }}{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 161 "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. Anothe r approach is" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "expr:=1/(1+x^4),x: Int(expr)=int(expr);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 110 "I f you are just interested in evaluating the integral then you can disp ense with 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." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 381 "It is worth noting too that sy mbolic solutions may be become very complex. If you end up with an exp ression with thousands of terms it may not be very useful and may take a long time to display, or even crash Maple. Always save your workshe et before executing a command which may lead to a very complex result, and consider requesting a numeric result when it makes sense to do so ." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 54 "Here 's a silly example of a moderately complex result:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "int((a+b*x+ c*log(x)+d*x*log(x))^12,x): nops(%); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 171 "The output means that th e expression for the integral has 3,185 terms in it. If you want to \+ see them, just replace the colon with a semicolon and re-execute the c omamnd." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "Some Plots" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 260 "" 0 "" {TEXT 278 124 "Functions and expressions can be plotted. T here are numerous plot variations. Check the help facility, ?plot, f or 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 col on above by semicolons and press Enter to generate the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 88 "We can convert \+ a function into an expression simply by evaluating 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 the colon above by a se micolon and press Enter to generate the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 117 "You can also plot anonym ous functions, or expressions, that is, plot them without first assign ing 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 demonstrated below, but \+ if you need something else, you will have to explore Maple 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 ha s a number of built-in plot commands. Additional commands are made ava ilable by loading the plots package (by means of the with(plots) comma nd)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "H ere 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 parametric plots. We will use parameters t and p, so lets make sure first they have not bee n assigned to some other expressions (otherwise we will get incomprehe nsibe error messages)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "t:=evaln(t): p:=evaln(p):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 73 "plot3d([4*cos(t)*sin(p),4*si n(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 other plot comma nds are available. Check ?plots. A nice plot to experiment with is th e 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 "N ote you can drag the plot around with the mouse to see the surface fro m 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 "tubeplo t([2*cos(t),2*sin(t),1],t=0..2*Pi-1/2,radius=1,numpoints=60);" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 36 "Taylor Series and Taylor Polynomi als" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 0 "" }{TEXT 276 0 "" }{TEXT -1 274 "Maple c an compute Taylor and interpolation polynomials. Actually the Taylor p olynomial is a special case of an interpolation polynomial, with all t he nodes equal. but Maple's interpolation routine requires distinct no des (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 a n example of Taylor polynomials:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "tay1:=taylor(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 te rms omitted. Parameters may be included:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "a:=evaln(a);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "tay2:=taylor(exp(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 it assigned to some number above. If I had not unevaluated it then Maple would ha ve substituted the value of a in this expression." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 132 "The data type returned b y taylor() is a series, not a polynomial. If you want a polynomial 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 reserved name (f or a data type) so you do not have to worry that you might have assign ed a value to it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "You can specify a different center, even a symbolic 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 "tay lor(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 interpolation 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 "The first para meter we pass to interp() is the list of (distinct) abscissas, the sec ond 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 polynomial function r ather than a polynomial expression in some variable, you can use unapp ly():" }}{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 "Le t'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 "I f you have a list of points you want to interpolate you can extract th e abscissas and ordinates by using the op() command (it lists the oper ands 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 lists, X X 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(Y Y),pnt[2]]; od:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 252 "Here pnt is a list with two entries (it represent s 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 alright" }} {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 "plot(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 interpolation poly nomial for a function is to use the map() command to evaluate the func tion 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 evalf() to \+ force (approximate) evaluation of the sine. Otherwise we will get 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,ti tle=\"Interpolation (red) of sin(t) (blue)\",color=[red,blue]);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 79 "No te the previous example shows one way of plotting two functions on one graph." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 21 "Interpolation Spline s" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 277 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 32 "Linear Algebra ( linalg package)" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 428 "We will be doing some li near algebra, so we load the linear algebra library, linalg. This libr ary defines some of the commands and data structures that we will use. When we load a library it announces all of the commands that it defin es. We can suppress this output by using a colon, in place of the usua l command-terminanting semicolon. Here I used a semicolon so you can s ee the list of commands defined by the linalg library." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(l inalg);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 196 "Matrices can be entered by listing their rows (lists are denoted by [ ] in Maple) or by giving the size and then listing the e ntries in the matrix row-wise. Here I enter the matrix A in both ways. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "A:=matrix([[1,2,3,4],[0,-1,3,4],[2,-1,2,3]]);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "A:=matrix(3,4,[1,2,3,4,0,-1, 3,4,2,-1,2,3]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 91 "It is also possible to build a matrix by specifying \+ its columns (as vectors or lists). Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "a[1]:=[1,0,2]; a[2]:=[ 2,-1,-1]; a[3]:=[3,3,2]; a[4]:=[4,4,3];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 51 "Now we use the augment co mmand to build the matrix:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "A:=augment(a[1],a[2],a[3],a[4]);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 130 "Alternately we can build the matrix by defining its rows and then sta cking them on top of each other with the stackmatrix command." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "b[1]:=[1,2,3,4]; b[2]:=[0,-1,3,4]; b[3]:=[2,-1,2,3];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "A:=stackmatrix(b[1],b[2],b[3]);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 187 " There is also a command called entermatrix which may be used to build \+ a matrix. It is a special purpose command though and not very convenie nt unless you enjoy typing numerous semicolons." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 50 "Diagonal matrices can be \+ entered in a natural way." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "diag(1,2,3,4);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 89 "The diag command g ives you a simple way to define your own n by n identity matrix, IE(n) :" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "IE:=n->diag(seq(1,k=1..n));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "IE(2); IE(3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 122 "It would have been more natura l to use I for the identity matrix, but Maple uses that for the squa re root of minus one. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 138 "Maple has a built-in command, rref, for computing \+ the row reduced echelon form of a matrix. For example, for the matrix \+ A above we have" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 8 "rref(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 152 "Note we still have A available. O rdinarily in Maple an expression may be evaluated (or the value recall ed) by entering the name followed by a semicolon." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 251 "A s we see, Maple makes an exception for matrices. The reason is they ca n be quite large and you may not wish to waste time displaying them, n or to clutter up your worksheet. You can always use the evalm function to force matrix evaluation and display." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalm(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 106 "Now supp ose we want to row reduce A ourselves. We'd want to add -2 times the first row to the third row:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "A1:=addrow(A,1,3,-2);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 469 "N ote I assigned the result to A1 so I would be able to refer to it in t he next step. An alternative approach is to use the ditto operator, %, but it is risky to use except within the same line, because it refers to the previous expression evaluated, which may not be the previous e xpression on your worksheet if you have done a lot of editing. Here's \+ an example of using the % operator. I stack up two commands on one lin e, so I will not have to worry what % points to." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "addrow(A1,2 ,1,2); A2:=addrow(%,2,3,-5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "mulrow(A2,2,-1); A3:=mulrow(%,3,-1/19);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "addrow(A3,3,1,-9); A4:=addrow(%,3,2,3);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "W e did not have to swap any rows here, but the command for that is swap row. Here is an example using again our matrix A." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "swaprow(A,1 ,3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 65 "Consider now a system of the form Ax=b, using again our matrix \+ A." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "b:=[2,7,-5];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "soln:=linsolve(A,b);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 239 "Maple returns a list of values. The unde rscore t sub 1 is a parameter. You assign it arbitrary values to obtai n all the solutions. If you find the expression difficult to read you \+ can always substitute something more agreeable, for example" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "s oln:=linsolve(A,b,rnk,s);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 204 "Note the parameter name has to appear as the fourth variable, so we had to insert a third variable, rnk, in th e function call. It turns out that linsolve stuffs the rank of A into \+ the third variable. Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "rnk;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 49 "One can pick out the indi vidual components easily" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "soln[1]; soln[2]; soln[3]; soln[4]; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 54 "You can also use the command op() to extract operands:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "op( soln)[1]; op(soln)[2]; op(soln)[3]; op(soln)[4];" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "We can also solve \+ directly by row reduction of course -" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "M:=augment(A,b); R:=rre f(M);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 216 "Here we can read the solution easily. Moreover, we get t he canonical form of the solution, with the free variable as the param eter. This is not the form that Maple returned above (though it is equ ivalent, of course)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "for k from 1 to 3 do x[k]:=R[k,5]-R[k,4]* s; od; x[4]:=s;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "For more complicated situations this could get out \+ of hand and linsolve may be preferable, even if it returns a non-canon ical solution." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 143 "Note we do not have to use linsolve to find the rank of \+ a matrix. Maple has a command called rank. Let's generate a random mat rix to illustrate" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 19 "B:=randmatrix(5,7);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "rank(B);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 124 "Actually, it turns out that for a 5 \+ by 7 random matrix the probability of rank 5 is 1. In other words, it \+ is nearly certain!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "Consider now the vectors" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "u:=[2,1,-3, 1]; v:=[-1,3,5,0]; w:=[2,-1,1,-3]; b:=[-16,17,37,3];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 242 "We wish to wri te b as a linear combination of u, v, w if possible. First we form the matrix with columns u, v and w. Then we solve the system of linear eq uations with this matrix as the coefficient matrix and with b as the i nhomogeneous term." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "B:=augment(u,v,w); linsolve(B,b);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 82 "We see b = -3u + 6v -2w. What happens if there is no solution? Here's a n example:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 35 "C:=matrix(2,2,[1,1,1,1]); b:=[1,2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "linsolve(C,b);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 19 "rref(augment(C,b));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 106 "There is no solution \+ and therefore Maple returns no response! It's logical, but may take g etting used to." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 253 "We have discussed m atrix multiplicatio a little bit in class already. In Maple the notati on for matrix multiplication is &*. It looks strange, but the ampersa nd warns Maple's symbolic simplification routines that this multiplica tion is non-commutative." }}{PARA 0 "" 0 "" {TEXT -1 22 "Here's a few \+ examples:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 39 "A:=randmatrix(3,3); B:=randmatrix(3,3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "evalm(A &* B); evalm(B &* A);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 236 "N otice I had to force Maple to evaluate these expressions. The default \+ behavior is to return the product unevaluated. This is very useful beh avior in some cases where intermediate results are inconveniently larg e or not actually needed." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 27 "Consider \+ now three vectors:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "c1:=vector([1,2,3]); c2:=vector([0,1,4]); c 3:=vector([1,3,7]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 83 "Are they linearly independent? We row reduce th e matrix with columns c1, c2 and c3." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "C:=augment(c1,c2,c3); rre f(C);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 215 "Since C has only 2 pivotal columns the vectors c1, c2 an d c3 are linearly dependent. Suppose we want to solve the system Cx=b. We know that there will be a compatability condition on b. Let's try \+ it with b symbolic." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "b:=vector([b1,b2,b3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "linsolve(C,b);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 62 "No response! Wise, but \+ not useful. Let's try another approach." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "rref(augment(C,b));" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 327 "That's strange. This result implies no solutions at all, yet there ce rtainly is a solution if b = 0 for example. The problem is that Maple \+ simplifies expressions such as z/z to 1 when z is symbolic. Thus Maple 's answer is actually correct in the sense that there is no solution w hich is a rational expression in b1, b2 and b3. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 211 "One way out of the impas se is to note that we can keep track of the coefficients of b1, b2 and b3 during row reduction by keeping them in separate columns. Thus we \+ augment C by an identity matrix and row reduce." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "augment(C,I E(3)); R:=rref(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 133 "There is no pivot in the first 3 columns in the \+ last row, so the remaining part of the last row yields a compatability condition on b" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 39 "evalm(submatrix(R,3..3,4..6) &* b) = 0;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 41 "No w we can read of the solutions easily. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 311 "One comment - Maple commands are polymorphic. Their behavior depe nds on the number and type of parameters that you feed to them. Howeve r, even though lists and vectors are different data types in Maple, th e linear algebra routines for the most part do not care which you use \+ and return the appropriate solution." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 143 "The type() function may be used to che ck data-types. This is useful in your own code if you want it to behav e reasonably with different inputs." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "a:=[1,2,3]; b:=vector([1,2 ,3]); c:=matrix(1,3,[1,2,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "type(a,vector); type(a,list); type(a, array); type(a,matrix);" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "type(b,vector); type(b,lis t); type(b,array); type(b,matrix);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "type(c,vector); type(c,list); type(c,array); type(c,m atrix);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 131 "If you get really mysterious results try thinking hard a bout your data types. Sometimes a lack of clarity in thought will bite you!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 118 "Another thing to watch out for is 0. When Maple multiplies a symbolic expression by 0 the result is 0. But which zero?" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "0*p;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 45 "Th is behavior can cause problems. For example" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "N:=matrix(2,2,[1, 2,3,4]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "0*N; evalm(3*N) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 215 "Ouch! Multiplying by 3 works fine, but our 2 by 2 matrix became a scalar when we multiplied by 0. Some very strange error messages co uld result later! Here the solution is to use the scalar multiplicatio n function" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 31 "scalarmul(N,0); scalarmul(N,3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 291 "Of course, it is rare for people to be so careful all the time. The key is to think ab out your results, to understand what is going on and to add the right \+ level of precision to guarantee your results. Even with computer algeb ra systems there is no substitute for understanding (or thought)." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 38 "For help with the linalg package try: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "?linalg" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 232 "Maple (at least version 6 and higher) ha s another linear algebra package called LinearAlgebra. It duplicates \+ some of the features of linalg but is better suited for numeric calcul ations with large matrices. For more information try" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "?LinearAl gebra" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{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 limited understa nding 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 "As above, we c an use the inert (unevaluated) form of limit(), i.e., Limit(), to do f ancy 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 "Here 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..infinity): %=value(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "sum(1/k^1.0002,k=1..infin ity);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "Int(exp(-x^4),x=0. .infinity): %=value(%);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 22 "Recu rsion and remember" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "We can 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 "and 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:=[o p(L),T(k)]: od: L;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 158 "Note here op(L) returns the operands in L, th en we tack on T(k) and form a list by enclosing everything in square b rackets, 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 remember option, \+ then Maple will remember results from previous incantations of the pro cedure (there are many since it calls itself) and therefore run quicke r (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 differ from mine, but y ou 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 quic k." }}{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 com pute TT(n) for too large an n Maple will return an error, \"Too ma ny levels of recursion.\" It is not always a good idea to define a fun ction recursively, even when it is slick." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "Set Theory" }}{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 our own absolute com plement function (relative to our selected universe):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "compleme nt:=X->U minus X;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "comple ment(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 "complement(A union B) inters ect 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 symmetric difference measu res by how much two sets differ. We can easily define our own symmetri c 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 "symdiff(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 ea sily 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 pro cedure carp() to compute the Cartesian product. This is a bit more com plicated than the arrow notation for functions, but is much more flexi ble." }}{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 "carp(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 devise our own t est 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 " for 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 "subset(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 "H ere'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 "subset 2:=(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 computed by using \+ the Maple function choose() from the the combinat package. To use it \+ we have either to load the combinat package by issuing the command wit h(combinat) or we have to call the function by using its so called lon g name combinat[choose](). We will use the second method but we will r ename the function to the more convenient powset()." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "alias(pow set=combinat[choose]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "p owset(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 121 "Try to be reasonable. If you decide to compute powset(c arp(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 million elements." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 144 "We have barely scratched the surface of Maple. There are many other things Maple can do. Try exploring the help facility. Above all, experiment!" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{MARK "27" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }