{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "2D Output" -1 20 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }{CSTYLE "_cstyle1" -1 202 "Times" 1 16 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle2" -1 203 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle3" -1 204 "Times" 1 14 0 0 0 1 2 1 1 2 2 2 0 0 0 1 }{CSTYLE "_cstyle4" -1 205 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle5" -1 206 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "_cstyle6" -1 207 "Times" 1 12 0 0 255 1 0 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle7" -1 208 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle8" -1 209 "Courier" 1 12 255 0 0 1 2 1 2 2 1 2 0 0 0 1 }{CSTYLE "_cstyle9" -1 210 "Courier" 1 12 255 0 255 1 0 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle10" -1 211 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 }{CSTYLE "_cstyle11" -1 212 "Times" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle12" -1 213 "Times" 1 14 0 0 0 1 2 1 1 2 2 2 0 0 0 1 }{CSTYLE "_cstyle13" -1 214 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle14" -1 215 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle15" -1 216 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{PSTYLE "_pstyle1" -1 200 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 0 0 1 }3 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{PSTYLE "_pstyl e2" -1 201 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{PSTYLE "_pstyle3" -1 202 1 {CSTYLE " " -1 -1 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 1 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{PSTYLE "_pstyle4" -1 203 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }3 3 0 -1 -1 -1 1 0 1 0 2 2 -1 1 } {PSTYLE "_pstyle5" -1 204 1 {CSTYLE "" -1 -1 "Courier" 1 12 255 0 255 1 0 0 0 2 2 1 0 0 0 1 }1 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "_psty le6" -1 205 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }0 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }} {SECT 0 {EXCHG {PARA 200 "" 0 "" {TEXT 202 29 "Math 365D Lab One - Fal l 2007" }{TEXT 203 0 "" }}{PARA 201 "" 0 "" {TEXT 203 0 "" }{TEXT 203 216 "\nMaple contains thousands of mathematical commands in areas rang ing from calculus to number theory to finance. We will begin with a fe w basics, then concentrate on programming with specific attention to g raph theory." }{TEXT 204 0 "" }{TEXT 204 1 "\n" }{TEXT 204 12 "\nSOME \+ BASICS" }{TEXT 203 0 "" }{TEXT 203 3 "\nA " }{TEXT 205 9 "semicolon" } {TEXT 203 2 " (" }{TEXT 205 1 ";" }{TEXT 203 66 ") at the end of a com mand causes the output to be printed while a " }{TEXT 205 5 "colon" } {TEXT 203 2 " (" }{TEXT 205 1 ":" }{TEXT 203 29 ") suppresses the outp ut. The " }{TEXT 205 5 "ditto" }{TEXT 203 42 " operator, represented b y a percent sign (" }{TEXT 205 1 "%" }{TEXT 203 56 "), refers to the l ast expression computed by Maple. The " }{TEXT 205 5 "sharp" }{TEXT 203 9 " symbol (" }{TEXT 205 1 "#" }{TEXT 203 28 ") allows the user to put in " }{TEXT 205 8 "comments" }{TEXT 203 27 " that are ignored by \+ Maple." }{TEXT 203 0 "" }}{PARA 201 "" 0 "" {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 42 "13!; # compute and display 13*12*11*. .*2*1" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"++3-F i" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 62 "is prime(%); # ask if the previous expression is a prime number" } {MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%&falseG" } {TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 61 "Expressions, \+ such as the previous one, that return values of " }{TEXT 208 5 "true \+ " }{TEXT 203 3 "or " }{TEXT 208 5 "false" }{TEXT 203 62 " are called B oolean expressions - more on them in a later lab." }{TEXT 203 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 203 19 "We use the symbols " }{TEXT 205 2 ":=" }{TEXT 203 40 " to assign an expression to a variable. " } {TEXT 203 0 "" }}{PARA 201 "" 0 "" {TEXT 203 102 "By pressing SHIFT-EN TER instead of ENTER, we get a new line without displaying any output, as follows." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 70 "x:=(a+b)^8: # assign this to the variable x but don't display anythin g" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 51 "\nexpand(x); # expand this expression and display it" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 1 "\n " }}{PARA 203 "" 1 "" {XPPMATH 20 "6#,4*$%\"aG\"\")\"\"\"*&F%\"\"(%\"b GF'F&*&F%\"\"'F*\"\"#\"#G*&F%\"\"&F*\"\"$\"#c*&F%\"\"%F*F4\"#q*&F%F1F* F0F2*&F%F-F*F,F.*&F%F'F*F)F&*$F*F&F'" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 89 "y:=evalf[50](Pi); # a floating point \+ evaluation of the expression to fifty decimal places" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"yG$\"S^P*Rpr>%)G]zKQVEYQKz *e`EfTJ!#\\" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 167 "It will often be useful (especially when using some of the built- in graph theory commands) to clear Maple's memory of the values of all variables. We do this with the " }{TEXT 205 7 "restart" }{TEXT 203 9 " command." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 8 "re start;" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 64 "y; # Maple will no longer remember what we assigned to y earli er" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%\"yG" } {TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 200 "When we open a Maple worksheet that has been saved, we could execute the commands \+ on an individual basis by hitting ENTER on each line, but there is als o a way to execute the entire worksheet at once." }{TEXT 203 0 "" } {TEXT 203 1 "\n" }{TEXT 203 280 "\nGo back and comment out (with a #) \+ the line with the restart command and then execute the entire workshee t by using the pull-down menu sequence EDIT:EXECUTE:WORKSHEET. Maple w ill execute every command in this worksheet and thus should now know t he expression assigned to y above." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 2 "y;" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%\"yG" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 204 10 "PROCEDURES" }{TEXT 203 0 "" }{TEXT 203 40 "\nWe will do \+ our programming by creating " }{TEXT 205 10 "procedures" }{TEXT 203 45 " as the following simple example illustrates." }{MPLTEXT 1 209 0 " " }{MPLTEXT 1 209 45 "\nraise:=proc(a::integer,b::integer)::numeric;" }{MPLTEXT 1 209 0 "" }{MPLTEXT 1 209 50 "\ndescription \"computes a ra ised to the bth power\";" }{MPLTEXT 1 209 0 "" }{MPLTEXT 1 209 34 "\n \+ a^b; # returns a^b" }{MPLTEXT 1 209 0 "" }{MPLTEXT 1 209 10 "\nend proc:" }{TEXT 203 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 11 "raise(3,5);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"$V#" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 12 "The objects " }{TEXT 205 2 "a " }{TEXT 203 4 "and " } {TEXT 205 2 "b " }{TEXT 203 11 "are called " }{TEXT 205 17 "formal par ameters" }{TEXT 203 48 ", and it is considered good form to give each \+ a " }{TEXT 205 16 "type declaration" }{TEXT 203 68 " (integer in this \+ case). We have also given the procedure itself a " }{TEXT 205 15 "typ e assertion " }{TEXT 203 10 "(numeric [" }{TEXT 208 5 "i.e.," }{TEXT 203 116 " integer or fraction or floating(decimal)] here), which tells Maple what sort of object the procedure should return." }{TEXT 203 0 "" }{TEXT 203 1 "\n" }{TEXT 203 57 "\nOnce the procedure is invoked (b y executing the command " }{TEXT 205 10 "raise(3,5)" }{TEXT 203 41 "), the formal parameters are replaced by " }{TEXT 205 9 "arguments" } {TEXT 203 4 " or " }{TEXT 205 17 "actual parameters" }{TEXT 203 11 " ( 3 and 5)." }{TEXT 203 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 77 "raise(3,sqrt(2)); # notice what happens if we try to pass an i nvalid argument" }{MPLTEXT 1 206 0 "" }}{PARA 204 "" 1 "" {TEXT 210 100 "Error, invalid input: raise expects its 2nd argument, b, to be of type integer, but received 2^(1/2)" }{TEXT 210 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 56 "Now go back and change the procedure's type \+ assertion to" }{TEXT 205 1 " " }{TEXT 203 20 "integer and execute " } {TEXT 205 11 "raise(5,-1)" }{TEXT 203 1 "." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 12 "raise(5,-1);" }{MPLTEXT 1 206 0 "" }} {PARA 203 "" 1 "" {XPPMATH 20 "6##\"\"\"\"\"&" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 203 234 "So, why didn't this give an er ror? By default, Maple does not check for procedure type assertion. To activate such checking, we need the following command, which you shou ld get in the habit of executing at the start of each worksheet." } {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 28 "kernelopts(ass ertlevel=2); " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 " 6#\"\"!" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 22 "We' ve now changed the " }{TEXT 205 11 "assertlevel" }{TEXT 203 40 " to 2, and Maple has displayed what the " }{TEXT 211 8 "previous" }{TEXT 203 163 " value of assertlevel was. To confirm that we're now at level 2, we execute the following. (For more details on kernelopts and asse rtlevel, please see Maple Help.)" }{TEXT 203 0 "" }}{PARA 202 "> " 0 " " {MPLTEXT 1 206 24 "kernelopts(assertlevel);" }{MPLTEXT 1 206 0 "" }} {PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"#" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 31 "Now go back and re-execute the " } {TEXT 205 12 "raise(5,-1) " }{TEXT 203 46 "command, which should give \+ an error this time." }{TEXT 203 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 204 15 "DECISION-MAKING" }{TEXT 203 0 "" }{TEXT 203 5 "\nThe " } {TEXT 205 12 "if ... then " }{TEXT 203 81 "statement allows us to perf orm an operation only when a certain condition is met." }{TEXT 203 0 " " }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 21 "pos:=proc(a::intege r)" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 63 "\ndescription \"outputs ' positive' if and only if a is positive\";" }{MPLTEXT 1 206 0 "" } {MPLTEXT 1 206 30 "\nif a>0 then print(\"Positive\")" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 8 "\nend if;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 10 "\nend proc:" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 " " {MPLTEXT 1 206 7 "pos(5);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#Q)Positive6\"" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 43 "Note the distinction between the procedure " } {TEXT 205 5 "raise" }{TEXT 203 19 " and the procedure " }{TEXT 205 3 " pos" }{TEXT 203 2 ". " }{TEXT 205 5 "raise" }{TEXT 203 1 " " }{TEXT 211 7 "returns" }{TEXT 203 36 " a value; this is similar to making " } {TEXT 205 5 "raise" }{TEXT 203 122 " the name of a function which then takes on a certain value (243 above) after the procedure is called. O n the other hand, " }{TEXT 205 3 "pos" }{TEXT 203 9 " doesn't " } {TEXT 211 6 "return" }{TEXT 203 199 " anything; instead, one of the co mmands within this procedure displays the word \"Positive\" under cert ain conditions. This distinction will become more clear as we see fur ther examples in later labs." }{TEXT 203 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 4 "The " }{TEXT 205 20 "if ... then ... else" }{TEXT 203 259 " statement gives additional flexibility. We can also \"nest\" if statements within if statements repeatedly if we need to examine s everal cases. We will look more fully at nesting in a later lab, but y ou can probably figure it out on your own today if you wish." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 77 "absolutevalue:=proc( x::float)::float; # the type 'float' lets us use decimals" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 47 "\ndescription \"outputs the absolute va lue of x\";" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 18 "\nif x >= 0 then x " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 16 "\n else -x" } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 8 "\nend if;" }{MPLTEXT 1 206 0 " " }{MPLTEXT 1 206 10 "\nend proc:" }{MPLTEXT 1 206 0 "" }}}{PARA 205 " " 0 "" {TEXT 212 0 "" }}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 20 " absolutevalue(-5.6);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#$\"#c!\"\"" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 " " {TEXT 203 24 "What happens if you try " }{TEXT 205 17 "absolutevalue (-5)" }{TEXT 203 1 "?" }{TEXT 203 0 "" }}}{PARA 205 "" 0 "" {TEXT 213 9 "EXERCISES" }{TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 214 98 "In the exercises for this and future labs, you will sometimes be asked to wr ite a procedure that \"" }{TEXT 214 8 "returns\"" }{TEXT 214 117 " an \+ object and sometimes asked to \"display\" or \"indicate\" something. T his is the difference that was mentioned above." }{TEXT 212 0 "" } {TEXT 212 1 "\n" }}{PARA 205 "" 0 "" {TEXT 214 47 "1. Write a procedur e that takes three integers " }{TEXT 215 1 "x" }{TEXT 214 2 ", " } {TEXT 215 1 "y" }{TEXT 214 6 ", and " }{TEXT 215 1 "z" }{TEXT 214 43 " as its arguments and returns the value of " }{TEXT 215 4 "xy+z" } {TEXT 214 1 "." }{TEXT 214 0 "" }{TEXT 214 60 "\n2. Write a procedure \+ that takes two floating-point numbers " }{TEXT 215 1 "a" }{TEXT 214 5 " and " }{TEXT 215 1 "b" }{TEXT 214 34 " as its arguments and returns \+ the " }{TEXT 215 1 "b" }{TEXT 214 11 "th root of " }{TEXT 215 1 "a" } {TEXT 214 1 "." }{TEXT 214 0 "" }{TEXT 214 35 "\n3. Write a procedure \+ that takes a " }{TEXT 216 6 "string" }{TEXT 214 156 " (any sequence of characters enclosed in double quotes, such as \"walrus\") as its argu ment and returns the third character of that string. Hint: look up the " }{TEXT 216 9 "substring" }{TEXT 214 26 " command in the Help menu. " }{TEXT 214 0 "" }{TEXT 214 143 "\n4. Write a procedure that takes a \+ floating-point number as its argument and then indicates whether that \+ number is positive, negative, or zero." }{TEXT 214 0 "" }{TEXT 214 110 "\n5. Write a procedure that takes two integers as its arguments a nd returns the value of the larger of the two." }{TEXT 214 0 "" } {TEXT 214 216 "\n6. Write a procedure that takes three floating-point \+ numbers as its arguments and returns the value of the largest of the t hree. Note: this may require some techniques slightly beyond those tau ght in the lab so far." }{TEXT 214 0 "" }{TEXT 214 67 "\n7. Write a pr ocedure that takes a positive integer (variable type " }{TEXT 216 6 "p osint" }{TEXT 214 81 ") as its argument and then displays either \"pri me\" or \"composite\" as appropriate." }{TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 8 " " }{TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT -1 0 "" }}}{MARK "0 0 0" 17 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }