{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 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "" 1 14 0 0 0 0 0 0 1 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 "" 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 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 266 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 } {CSTYLE "" -1 268 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 14 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 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 271 "" 0 14 0 0 1 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 272 "" 1 14 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 273 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 274 "Helvetica" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 275 "" 0 14 255 0 0 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 276 "" 0 14 0 0 1 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 277 "" 0 14 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 278 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 279 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 280 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 281 "" 1 14 0 0 255 1 0 0 1 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 2" -1 4 1 {CSTYLE "" -1 -1 "Times " 1 14 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 "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 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 "Normal" -1 258 1 {CSTYLE "" -1 -1 "T imes" 1 14 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Normal" -1 259 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 }{PSTYLE "Normal" -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 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 261 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 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 257 37 "MLC Lab Visit - Introdu ction to Maple" }}{PARA 0 "" 0 "" {TEXT 256 43 "Mth 355 (a.k.a. Mth 39 9) Oct 3 2001 Maple 6" }}{PARA 0 "" 0 "" {TEXT 258 16 "Bent E. Peterse n" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 29 "This document is available at" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 261 "" 0 "" {TEXT 273 41 "http://www.onid.orst.edu/~pe terseb/pclab/" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 268 200 "Some of the commands below may not work correctly in Ma ple 5 and earlier (the spline examples below, for example). Usually th ere are other ways to achieve the same effect. Check Maple's built-in \+ help." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 279 426 "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, all of Maple's output will be vi sible, (except some of the plots) so you can read along and make sense out of it." }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 12 "Introduction" }} {PARA 4 "" 0 "" {TEXT 26 0 "" }}{PARA 0 "" 0 "" {TEXT -1 386 "Maple is a CAS, that is, a Computer Algebra System. It performs mathematical o perations symbolically, but a large number of robust numerical routine s are also built in. Maple can be used interactively as a rather fancy calculator, but it can also be used as a flexible programming languag e. 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 206 "The workstations in the MLC lab are PCs runnin g Windows NT 4.0. You must have an ONID account or an ORST account to \+ use the PCs in the MLC lab. Since ORST is being phased out you should \+ get an ONID account." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 96 "When you logon to a machine in the MLC lab be sure the \+ correct domain is selected, ONID or ORST." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 254 "When you logon to a machine in th e MLC lab your ONID directory on the ONID server will be visible as dr ive Z: This is where you should keep your personal files. Then they wi ll 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 53 "Note there is a lab manual (currently out-of-date) at" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 261 "" 0 "" {TEXT 274 61 "http://www.o nid.orst.edu/~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 wa nt to look at it for interest sake. Note in spite of what it may say i n the lab manual your user NT user profile is no longer saved (nor res tored). Anything you want to save will have to be saved explicitly on \+ your drive Z: Whatever you save on the local drive will be available o nly on the machine you are working on, so don't save locally. Use the \+ Z: network drive." }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT 259 5 "Login" }}{PARA 0 "" 0 "" {TEXT -1 330 "The machines in th e 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-Delete key s simultaneously. You should get a login prompt. Enter your ONID user \+ name and press the Tab key (not the Enter key). Then enter your ONID p assword 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 slow n etwork connection. This message is bogus. Ignore it." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 164 "Next you may see a que stion about a default Novell server. Just answer \"none\" unless you h ave a reason to answer otherwise. This question should never appear ag ain." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 269 " To start Maple (or Matlab, or Mathematica, ... ) select the Start butt on (lower left corner of the screen), then Programs from the menu, etc . If you don't know the appropriate steps here ask for help. Writing a ll this out in detail produces an incredibly dull document." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 260 6 "Logout" }} {PARA 0 "" 0 "" {TEXT -1 250 "When you are done with your session save your work, shutdown the software you were using and logout. To logout select the Start button (this is a very strange Windows idiom), and t hen select \"Shut Down ...\" and finally select \"Logon as another use r.\"" }}{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 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 and do not shut off the PC. There i s no harm in shutting off the PC, but doing so causes the next user to have a long wait while the machine reboots. You may turn off the moni tor 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 f or 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 minutes, save your work to the Z: \+ drive and logoff. When you return and logon, even to a different machi ne, your work will be available. Do not select \"Lock Workstation.\" I f you do, someone else wishing to use the workstation may power-cycle \+ it in order to gain access and your unsaved work may be lost as a resu lt. The same comments apply to relying on a password protected screens aver. Don't do it. Save your work and logoff. You have no claim on any workstation if you are not physically present." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 281 15 "Getting Started" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 507 "Scroll d own to the restart command below. Position the cursor on the line cont aing the restart command and press Enter. Maple will execute the resta rt command and then position the cursor on the next command, skipping \+ over all the intervening text. Now press Enter to execute the next com mand, etc., or be brave and edit it first. Experiment! Some of the com mands depend on previous assignments, etc. If you skip around and some thing 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 sample commands we re selected to illustrate a few Maple features to get you started usin g Maple. To learn more you should make heavy use of the online help. T he help is very good and usually includes a few examples." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 261 13 "The Worksheet" }} {PARA 257 "" 0 "" {TEXT -1 470 "When you are using Maple in a window e nvironment it is possible to move around on the worksheet by left-clic king the mouse. As a result, commands may end up being executed in a n onlinear order. This can cause some confusion, since there is no visua l clue. One way to fix a mess is to have Maple re-execute the whole wo rksheet (look on the Edit menu). This works best if old expressions ar e cleaned up first, so it is a good idea to start each worksheet with \+ the command " }{TEXT 262 7 "restart" }{TEXT 280 1 ";" }{TEXT -1 40 " Y ou do not need to do so of course ...." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 269 132 "Maple c ommands are executed by pressing the Enter key when the mouse cursor ( pointer, thumb) is in the line containing the commands." }{TEXT 271 76 " Note that Maple skips over the interpolated text comments (like t his one). " }{TEXT 275 139 "To execute the commands on this worksheet \+ position the mouse cursor on the command line and press Enter. Edit th e command first if you wish" }{TEXT 277 1 "." }{TEXT 276 72 " Explore! Simply waiting for something to happen will not be productive." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 239 "Note eac h Maple command must be terminated by a colon or a semicolon (except h elp commands preceded by a question mark). The effect of the colon is \+ to suppress output from the corresponding command, though the command \+ 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 post poning the terminating colon or semicolon. You simply move to a new li ne by pressing Enter. Maple will chatter at you when you move to a new line in this manner if the previous command is unterminated. Ignore i t, but keep in mind a command will not be executed before it is proper ly terminated." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 220 "You can also stack up several commands on one line by te rminating them individually with colons or semicolons. All the comman ds on a line are executed when you press the Enter key (with the curso r 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 command \+ line below the current one by pressing Ctrl-J, or above the current li ne, by pressing Ctrl-K. This is pretty useful when you realize you omi tted something at a certain step." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 4 "" 0 "" {TEXT -1 30 "Assignment and Ditto Operators" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 129 "The assignment operator in maple is := (colon and equals sign juxtaposed). The equal s sign by itself does not perform assignment." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 248 "Maple has two ditto oper ators, % and %%. The value of % is the previously evaluated expressi on, the value of %% is the one before that. Since the Worksheet comm ands may be executed in any order, the ditto operators can cause a lot of confusion." }{TEXT 278 1 " " }{TEXT 270 87 "It is probably best to restrict them to the same line as the expressions they refer to." } {TEXT -1 74 " Here is a silly example, which also demonstrates the ass ignment 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 unas sign variables. Right now a is 5. That would cause problems if we w ant to use a as a dummy variable 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 pass any number of variables to the unassign() command." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 114 "A simpler way to unassign one variable is to assign it its name e xtracted by single quotes (this is a Maple idiom)" }}{PARA 0 "" 0 "" {TEXT -1 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 222 "Here the error comes from trying \+ to assign 4 to 3. The expression 3=4 causes no problem though. It is s imply an expression. The 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);" }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 " " {TEXT -1 9 "Constants" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 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 108 "Note the upper case lett ers. If you enter pi you will just get the Greek letter pi, not the re al 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 optiona l. If it is not specified then the global constant Digits is used (the default value is 10, but you can assign any positive integer value (u p 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 119 "Note 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 "" }}{PARA 4 "" 0 "" {TEXT -1 6 "Digits" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 238 "You set the Maple's floating point precision by \+ assigning a value to Digits (the default is 10). Maple usually does ex act calculations, but when floating point numbers are involved then Di gits 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 0 "" }}{PARA 0 "" 0 "" {TEXT -1 103 "T he label \"rational\" is protected in Maple 6. You can not assign a va lue to it (which is just as well)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 37 "Let's set Digits back to its default." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "Digits:=10:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 " " 0 "" {TEXT -1 38 "Functions and Expressions. Derivatives" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 91 "Maple distinguish es between functions and expressions. Here's one way to define a funct ion:" }}{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 33 "We can also define an expressio n:" }}{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 assume that x has not already been assigned a value. It needs to be an una ssigned variable. In the definition of f the x is a dummy variable , a place marker. In g however, it is part of the expression, and on e 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 convent ion. To evaluate an expression one generally uses the subs() command ( 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));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 134 "Some Maple commands work on expressions, some work on functions, and some on both. For example , here are the derivatives of f and g." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "D(f); diff(g,x);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 33 "S econd 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 "b ut this notation can get out hand. Fortunately there is an alternative ! 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 also easily \+ computed (here once relative to y and three 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 415 "There is an inert version Diff() \+ of diff(). An inert function returns unevaluated. That may seem strang e, but sometimes one can save time by postponing evaluation, or one ca n prevent Maple from attempting a calculation that will fail at presen t, but can be carried out later in special cases or different contexts . Unevaluated expressions may be evaluated by using the command value( ), thought there are other 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 ca n 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(%) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 11 "Integration" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 263 "Let's bring back some fond memories from calculus - the \+ problem of integration. Here's an example to get you started: Once aga in I use postponed evaluation to get a nicely typeset equation. You do n'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 e ffect 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 "i f you don't mind writing the integrand twice. In both these example th e equals 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 are just interested in evaluating the integral then you can dispen se 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 139 "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 45 "int(arctan(x)/log(x),x=Pi/8..Pi/4); evalf(%);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "evalf(Int(arctan(x)/log(x),x =Pi/8..Pi/4));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 500 "Here, in the first case, Maple decided after a whil e (possibly a long while) that it can not return a symbolic value for \+ the integral and so returned it unevaluated. Then evalf() called a num eric quadrature rule to get an answer. In the second case however, Map le wasted no time trying to find a nonexistent symbolic solution, but \+ instead used a numeric quadrature method. This is an important use of \+ inert functions. You can grow noticably older waiting for a symbolic s olution to a complex problem." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 137 "There are refinements. For example, you \+ can specify what quadrature method to use. Enter the command ?int[nume ric] for more information." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 4 "" 0 "" {TEXT -1 8 "Plotting" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 124 "Functions and expressions can \+ be plotted. There are numerous plot variations. Check the help facili ty, ?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 55 "plot(f,0..1,numpoints=200,ti tle=\"Plotting a function\");" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "plot(g,x=0..1,numpoints=200,title=\"Plotting an expression\"):" }}}{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 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 semicolon and press Enter to generate the plot." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 117 "You can also plo t anonymous functions, or expressions, that is, plot them without firs t 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 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 "" }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 29 "Taylor Series and Polynomials" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 264 0 "" } {TEXT -1 274 "Maple can compute Taylor and interpolation polynomials. \+ Actually the Taylor polynomial is a special case of an interpolation p olynomial, 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:= 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 terms 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 the n Maple 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 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 (for a data type) so you do not have to worry that you m ight have 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 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 "taylor(exp(x),x=c,4): pc:=convert(%,polynom);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 25 "In terpolation Polynomials" }{TEXT 263 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 75 "Maple provides a built-in command fo r 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 parameter we pass to interp() is the list of (distinct) abscissas, the second is the list of ordinates and the thi rd 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 y ou want a polynomial function rather than a polynomial expression in s ome 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 interpol ate you can extract the abscissas and ordinates by using the op() comm and (it lists the 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 tw o empty lists, XX and YY, and then push the abscissas on XX and the or dinates 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),pn t[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 entri es (it 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 t he 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 "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." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 21 "Interpolation Splines" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 265 0 "" }{TEXT -1 267 "Maple computes splines of all degrees - check the help. Here w e will look only at linear and (natural) cubic splines. A linear splin e is just a piecewise linear function. The parameters are much the sam e 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:=spline(XX,YY,x,linear);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "sp3:=spline(XX,YY,x,cubic);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 135 "plot([sp1,sp3],x=1..5,color=[red,blue],thic kness=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 smoothe ns out the graph without introducing too much oscillation. If we compa re the piecewise linear spline and the interpolation polynomial we see unreasonable oscillation 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 l inear (red) and polynomial interpolation (blue)\"):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 76 "Replace the col on above by a semicolon and press Enter to generate the plot." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 203 "Note the vertical scales are different in the two graphs. We can plot all thre e function in one graph for a more convincing demonstartion of how wel l the cubic spline 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=\"red=piecewise linear, blue=cubic spline, black=interpolat ion 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 generate 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 l inear and the cubic spline just about merge on the graph)." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 30 "Trapezoid al and Simpson's Rule" }{TEXT 266 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 229 "Maple has numerous high-power quadra ture methods built in, but if one simply wants to experiment with the \+ trapezoidal rule or Simpson'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 eas y 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 th e student package." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "unassign('f');" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 15 "with(student): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "trapezoid(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 student package. This package contains the code for the trap ezoidal, Simpson's rule and many other things. It is a standard part o f 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 her e." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 10 "More Plots" }{TEXT 272 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{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 comam 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 "" {TEXT -1 0 "" }}{PARA 4 " " 0 "" {TEXT -1 17 "Sums and Products" }{TEXT 267 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 57 "Maple can compute quit e 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 "T hese three examples illustrate different ways of achieving the same ty pographical effect. Note that sum() computes a sum, whereas Sum() simp ly returns unevaluated. The first example also shows that you can assi gn 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 "pro duct(k/(k+1),k=1..n); simplify(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 13 "Number Theory" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 167 "Maple has a some simpl e number theory support built-in. Additional resources are available i n the (standard) numtheory library (loaded by with(numtheory) if nee ded)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 128 "We can compute greatest common divisors, gcd, and least common multip les, lcm, of polynomials, and so in particular of integers." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "g cd(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 primality" }}{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 fa ctor integers" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ifactor(1337);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "ifactor(1111111111111111111111111111111111111111);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 82 " We can compute Mersenne primes, that is primes of the form 2^n-1 (n mu st 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 "I f you just want to list known Mersenne primes (Maple has a built-in li st) you can use a modified mersenne() 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' = ro und(evalf(log[2](mersenne([k])+1))); od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 33 "A bit of recursion and \" remember\"" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{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:=[op(L),T(k)]: od: L;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 158 "Note here op(L) r eturns the operands in L, then we tack on T(k) and form a list by enc losing everything 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 procedu re with the remember option, then Maple will remember results from pre vious incantations of the procedure (there are many since it calls its elf) and therefore 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 tim es will differ from mine, but you will see that TT is hundreds of ti mes faster than T. Keep the \"option remember\" in mind when doing re cursion. 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 idea to define a function recursively, even when it is slick." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 6 "Limits" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 43 "Maple has a limited understanding of li mits" }}{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 can use \+ the inert (unevaluated) form of limit(), i.e., Limit(), to do fancy ty pography." }}{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(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 4 "" 0 "" {TEXT -1 17 "Solving Equations" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{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 23 "solve(sin(x) =cos(x),x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "solve(x^4+1= 0,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." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "We have barely scratched the surface. 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 "0 0 0" 37 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }