{VERSION 6 1 "Windows XP" "6.1" } {USTYLETAB {PSTYLE "Warning" -1 7 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 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 "Dash Item" -1 16 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 3 }{PSTYLE "Heading 4" -1 20 1 {CSTYLE "" -1 -1 "MS Serif" 1 12 0 0 0 0 1 0 0 2 2 2 0 0 0 1 }1 1 0 -1 0 0 1 0 1 0 2 2 -1 1 }{PSTYLE "Heading 3" -1 5 1 {CSTYLE "" -1 -1 " MS Serif" 1 14 0 0 0 0 1 1 0 2 2 2 0 0 0 1 }1 1 0 -1 0 0 1 0 1 0 2 2 -1 1 }{PSTYLE "Error" -1 8 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 "A uthor" -1 19 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }3 1 0 -1 8 8 1 0 1 0 2 2 -1 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "MS Serif" 1 16 0 0 0 0 0 1 0 2 2 2 0 0 0 1 }1 1 0 -1 8 2 1 0 1 0 2 2 -1 1 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 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 "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "MS Serif" 1 18 0 0 0 0 0 1 0 2 2 2 0 0 0 1 }1 1 0 -1 8 4 1 0 1 0 2 2 -1 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{PSTYLE "Maple Plot" -1 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "Line Printed Output" -1 6 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 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 "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 0 0 1 1 2 2 2 0 0 0 1 }3 1 0 -1 12 12 1 0 1 0 2 2 -1 1 }{PSTYLE "Map le Output" -1 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "List Item" -1 14 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 5 }{PSTYLE "Bullet Item" -1 15 1 {CSTYLE "" -1 -1 "Ti mes" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 2 } {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "2D Input" -1 19 "Times" 1 12 255 0 0 1 0 0 0 2 1 2 0 0 0 1 }{CSTYLE "Hyperlink" -1 17 "MS Serif" 1 12 0 128 128 1 0 0 1 2 2 2 0 0 0 1 }{CSTYLE "Text" -1 200 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 1 12 0 0 0 1 0 0 0 2 2 2 0 0 0 1 } {CSTYLE "Dictionary Hyperlink" -1 45 "MS Serif" 1 12 147 0 15 1 0 0 1 2 2 2 0 0 0 1 }{CSTYLE "Maple Input Placeholder" -1 201 "Courier" 1 12 200 0 200 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "2D Output" -1 20 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }{CSTYLE "Page Number" -1 33 "Times " 1 10 0 0 0 0 0 0 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 }{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 }{PSTYLE "_pstyle2" -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 } {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 } {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 }{CSTYLE "_cstyle5" -1 206 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 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 }{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 }{PSTYLE "_pstyle5" -1 204 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }3 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{CSTYLE "_cstyle8" -1 209 "Times" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }{PSTYLE "_pstyle6" -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 }{CSTYLE "_cstyle9" -1 210 "Times" 1 14 0 0 0 1 2 1 1 2 2 2 0 0 0 1 }{CSTYLE "_cstyle10" -1 211 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle11" -1 212 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle12" -1 213 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle13" -1 214 "Times" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }} {SECT 0 {EXCHG {PARA 200 "" 0 "" {TEXT 202 29 "Math 365D Lab Two - Fal l 2005" }{TEXT 203 0 "" }{TEXT 203 1 "\n" }}{PARA 201 "" 0 "" {TEXT 204 5 "LOOPS" }{TEXT 203 0 "" }{TEXT 203 3 "\nA " }{TEXT 205 11 "for . .. do " }{TEXT 203 86 "loop allows us to repeat a command (or sequence of commands) a given number of times. " }{TEXT 203 0 "" }{TEXT 203 1 "\n" }{TEXT 203 237 "\nUnlike the simpler procedures from our last lab , today's will require variables in addition to the arguments that are passed to the procedure when it is called. We declare these variables in the lines after the procedure description. A " }{TEXT 205 6 "local " }{TEXT 203 129 "variable is one that is used only within the proced ure and whose value is not retained and not accessible outside the pro cedure. " }{TEXT 203 0 "" }}{PARA 201 "" 0 "" {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 34 "addup:=proc(n::integer)::integer; " } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 50 "\ndescription \"sums the first n positive integers\";" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 34 "\nlo cal i::integer, total::integer;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 43 "\ntotal:=0; #initialize this variable" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 54 "\nfor i from 1 to n do # do what follows n times" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 32 "\n total:=tota l+i; " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 8 "\nend do;" } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 31 "\ntotal; # return the s um" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 10 "\nend proc:" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 10 "addup(10);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"#b" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 108 "print(total ); print(i); # since these were local variables, their values are not \+ known outside the procedure" }{MPLTEXT 1 206 0 "" }}{PARA 201 "" 0 "" {TEXT 203 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&totalG6\"" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I\"iG6\"" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 58 "Go back and change the varia ble declaration from local to " }{TEXT 205 7 "global " }{TEXT 203 96 " and remove the integer type declarations (MAPLE prefers not to attach \+ types to global variables)" }{TEXT 205 2 ". " }{TEXT 203 173 "Then pre ss ENTER anywhere in the procedure and press ENTER on each of the two \+ lines below that. Maple should now display the values of these variabl es outside the procedure." }{TEXT 203 0 "" }}{PARA 201 "" 0 "" {TEXT 203 0 "" }{TEXT 203 180 "\nIf we don't know in advance the exact numbe r of times we wish to repeat the command(s) in the loop, the for ... n ext loop won't work well. In such a situation, we can often use a " } {TEXT 205 13 "while ... do " }{TEXT 203 13 "loop instead." }{TEXT 203 0 "" }{TEXT 203 1 "\n" }{TEXT 203 58 "\nFor example, suppose that we w ish to print out the first " }{TEXT 208 1 "n" }{TEXT 203 160 " prime n umbers. We can't do a for ... next loop to check the integers from 1 t o n because that will result in fewer than n primes. Instead, we do th e following." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 31 "firstnprimes:=proc(n::integer) " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 43 "\ndescription \"displays the first n primes\";" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 54 "\nlocal primesfound::integer, currentinte ger::integer; " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 73 "\nprimesfound :=0; # this keeps track of how many we've found so far" } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 56 "\ncurrentinteger:=1; # this is the integer we're testing " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 64 " \nwhile (primesfound < n) do # do this until we've found n primes" } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 48 "\n if isprime(currentin teger) then " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 68 "\n \+ print(currentinteger):primesfound:=primesfound+1; " } {MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 16 "\n end if;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 78 "\n currentinteger:=currentintege r+1; # increment to look at next integer" }{MPLTEXT 1 206 0 "" } {MPLTEXT 1 206 8 "\nend do;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 69 " \nreturn; # try leaving this out and see how the output changes " }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 10 "\nend proc:" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 16 "firstnprimes (3);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"#" } {TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"$" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"&" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 204 30 "THE NETWORKS PACKAGE, PART ONE" }{TEXT 203 0 "" }{TEXT 203 33 "\nMaple contains a package called " } {TEXT 205 9 "networks " }{TEXT 203 64 "which includes many commands us eful in graph theory. We use the " }{TEXT 205 5 "with " }{TEXT 203 31 "command to invoke this package." }{TEXT 203 0 "" }{TEXT 203 1 "\n" }} {PARA 202 "> " 0 "" {MPLTEXT 1 206 85 "with(networks): # type this wit h a semicolon to see the list of all networks commands" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 127 "H:=graph( \+ \{a,b,c,d\}, \{\{a,c\}, \{b,b\}, \{c,d\}, \{d,a\}, \{a,b\}\}): # the f irst set is the set of vertices, the second the set of edges " } {MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 8 "dr aw(H);" }{MPLTEXT 1 206 0 "" }}{PARA 204 "" 1 "" {GLPLOT2D 400 400 400 {PLOTDATA 2 "60-%'POINTSG6#7$$\"\"\"\"\"!$F)F)-%%TEXTG6$7$$\"2-+++ +++?\"!#;$F)!\"\"Q\"a6\"-F$6#7$$!+3Q.^?!#>F'-F,6$7$$!+-+++?!#5$\"#5F3Q \"bF5-F$6#7$$F3F)$!+:w1-TF;-F,6$7$$!2-++++++?\"F1F2Q\"cF5-F$6#7$$\"+A9 5`hF;FH-F,6$7$$\"+1+++?FA$FAF3Q\"dF5-%'CURVESG6$7$F&FG-%&COLORG6&%$RGB GF2FBF2-Fhn6$7U7$$!\"#FAF'7$$!)*fqd\"FA$\"+Zm1D5!\"*7$$!)!oLG'FA$\"+xz t\\5Fjo7$$!*IqWS\"FA$\"+6\\it5Fjo7$$!*UmQZ#FA$\"+N2N'4\"Fjo7$$!*8g'>QF A$\"+]qb<6Fjo7$$!*ZF1U&FA$\"+@%4p8\"Fjo7$$!*B?:D(FA$\"+\\E5a6Fjo7$$!*7 kMG*FA$\"+&el)o6Fjo7$$!+=9W[6FA$\"+5a'4=\"Fjo7$$!+9g'>Q\"FA$\"+.8@!>\" Fjo7$$!+utBD;FA$\"+]uX'>\"Fjo7$$!+k*=W(=FA$\"+Y`g*>\"Fjo7$$!+T5eD@FAF` s7$$!+JEwuBFAF[s7$$!+!*R.=EFAFfr7$$!+&ee:&GFAFar7$$!+\"f`;2$FAF\\r7$$! +\")z%[F$FAFgq7$$!+fs$zX$FAFbq7$$!+#*R.=OFAF]q7$$!+jLh_PFAFhp7$$!+uHbf QFA$\"+5\\it5Fjo7$$!+Dj;PRFAF^p7$$!+0%HU)RFAFho7$$!+-+++SFA$\"+******* ***FA7$Ffu$\"+KNL\\(*FA7$$!+Cj;PRFA$\"+D-i-&*FA7$F^u$\"+&*3vj#*FA7$$!+ iLh_PFA$\"+_E\\O!*FA7$$!+\"*R.=OFA$\"+'\\HW#))FA7$$!+ds$zX$FA$\"+*y04j )FA7$$!+zz%[F$FA$\"+8N(*e%)FA7$$!+!f`;2$FA$\"+[TM6$)FA7$$!+$ee:&GFA$\" +%*eM!>)FA7$$!+*)R.=EFA$\"+np)y4)FA7$$!+IEwuBFA$\"+)\\Da.)FA7$$!+S5eD@ FA$\"+Vl%R+)FA7$$!+i*=W(=FAFcy7$$!+stBD;FA$\"+*\\Da.)FA7$$!+8g'>Q\"FA$ \"+op)y4)FA7$$!+>9W[6FA$\"+&*eM!>)FA7$Fjq$\"+\\TM6$)FA7$Feq$\"+9N(*e%) FA7$$!*XF1U&FA$\"+\"z04j)FA7$$!*6g'>QFA$\"+)\\HW#))FA7$$!*TmQZ#FA$\"+a E\\O!*FA7$$!*HqWS\"FA$\"+(*3vj#*FA7$$!)zO$G'FA$\"+G-i-&*FA7$Ffo$\"+NNL \\(*FA7$Fco$\"+++++5FjoF[o-Fhn6$7$FGFSF[o-Fhn6$7$F&FSF[o-Fhn6$7$F&F8F[ o-%*AXESSTYLEG6#%%NONEG" 1 2 2 0 10 1 2 6 1 1 2 1.0 45.0 45.0 1 0 "Cur ve 1" "Curve 2" "Curve 3" "Curve 4" "Curve 5" "Curve 6" "Curve 7" "Cur ve 8" "Curve 9" "Curve 10" "Curve 11" "Curve 12" "Curve 13" }}{TEXT 209 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 133 "The following comm ands will display the vertices and edges of a graph. Note that the set of edges may not appear as you would expect." }{TEXT 203 0 "" }} {PARA 202 "> " 0 "" {MPLTEXT 1 206 91 "vertices(H); # note that the br aces \{\} indicate this is a set - more on sets in a later lab" } {MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<&I\"aG6\"I\"cG F%I\"bGF%I\"dGF%" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 55 "vertices(H)[2]; # the [n] asks for only the nth ele ment" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I\"cG6\" " }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 9 "edge s(H);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<'I#e1G 6\"I#e2GF%I#e3GF%I#e4GF%I#e5GF%" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 " " 0 "" {TEXT 203 60 "In order to view the edges in a more useful way, \+ we use the " }{TEXT 205 5 "ends " }{TEXT 203 8 "command." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 11 "ends(e3,H);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<$I\"cG6\"I\"dGF%" } {TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 55 "ends(e 2,H); # note what happens when the edge is a loop" }{MPLTEXT 1 206 0 " " }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<#I\"bG6\"" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 203 212 "Maple will also generate rando m graphs and complete graphs. This is helpful when you would like to t est a procedure on many graphs without going to the trouble of typing \+ them all in as sets of vertices and edges." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 86 "J:=random(8,11): # first argument is \+ number of vertices, and second is number of edges" }{MPLTEXT 1 206 0 " " }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 59 "K:=complete(5): # t his is the complete graph on 5 vertices " }{MPLTEXT 1 206 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 8 "draw(J);" }{MPLTEXT 1 206 0 "" }}{PARA 204 "" 1 "" {GLPLOT2D 400 400 400 {PLOTDATA 2 "6>-%'P OINTSG6#7$$\"\"\"\"\"!$F)F)-F$6#7$$!+3Q.^?!#>F'-F$6#7$$!\"\"F)$!+:w1-T F0-F$6#7$$\"+A95`hF0F4-%'CURVESG6$7$F&F3-%&COLORG6&%$RGBG$F)F5$\"#5F5F E-F>6$7$F3F:FA-F>6$7$F&F:FA-F>6$7$F&F-FA-%%TEXTG6$7$$\"2-++++++?\"!#;F EQ\"16\"-F$6#7$$\"+6y1rq!#5$\"+8y1rqFin-FR6$7$$\"1)****4\"y1r!*FW$\"1- ++8y1rqFWQ\"2FY-FR6$7$$!+-+++?FinFFQ\"3FY-F$6#7$$!+6y1rqFinFjn-FR6$7$$ !+6y1r!*FinFaoQ\"4FY-FR6$7$$!2-++++++?\"FWFEQ\"5FY-F$6#7$$!+0y1rqFin$! +>y1rqFin-FR6$7$$!+0y1r!*FinF`qQ\"6FY-FR6$7$$\"+1+++?Fin$FinF5Q\"7FY-F $6#7$Fjn$!+5y1rqFin-FR6$7$$\"1+++8y1r!*FW$!*\"y1rq!\"*Q\"8FY-F>6$7$F&F \\pFA-F>6$7$F&F]qFA-F>6$7$F&FarFA-F>6$7$FfnF]qFA-F>6$7$F3FarFA-F>6$7$F \\pF3FA-F>6$7$F]qF:FA-%*AXESSTYLEG6#%%NONEG" 1 2 2 0 10 1 2 6 1 1 2 1.0 45.0 45.0 1 0 "Curve 1" "Curve 2" "Curve 3" "Curve 4" "Curve 5" "C urve 6" "Curve 7" "Curve 8" "Curve 9" "Curve 10" "Curve 11" "Curve 12" "Curve 13" "Curve 14" "Curve 15" "Curve 16" "Curve 17" "Curve 18" "Cu rve 19" "Curve 20" "Curve 21" "Curve 22" "Curve 23" "Curve 24" "Curve \+ 25" "Curve 26" "Curve 27" }}{TEXT 209 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 4 "The " }{TEXT 205 10 "neighbors " }{TEXT 203 65 "command \+ shows the vertices to which a given vertex are connected." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 16 "neighbors(d,H); " } {MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<$I\"aG6\"I\"cG F%" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 13 "Finally, the " }{TEXT 205 5 "nops " }{TEXT 203 133 "(\"number of operands\" - \+ not specific to the networks package) command counts the number of ele ments in whatever argument it is given." }{TEXT 203 0 "" }}{PARA 202 " > " 0 "" {MPLTEXT 1 206 18 "nops(vertices(H));" }{MPLTEXT 1 206 0 "" } }{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"%" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 152 "nops(neighbors(vertices(H)[1], H)); # here we nest several commands in order to display the number of neighbors of vertex 1 (the vertex we've called 'a')" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"$" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 203 116 "The procedure that follows dem onstrates how the built-in networks commands can make working with gra phs much easier." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 28 "twoneighbors:=proc(G::graph)" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 69 "\ndescription \"displays all vertices that have exactly two \+ neighbors\";" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 63 "\nlocal numvert ices::integer, i::integer, currentvertex::vertex;" }{MPLTEXT 1 206 0 " " }{MPLTEXT 1 206 76 "\nnumvertices:=nops(vertices(G)); # the total nu mber of vertices in the graph" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 51 "\nfor i from 1 to numvertices do # check each vertex" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 61 "\n currentvertex:=vertices(G)[i]: \+ # pick the ith vertex" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 80 "\n \+ if nops(neighbors(currentvertex,G))=2 then print(currentvertex) en d if;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 67 "\n # these two \+ lines could have been nested into one as above" }{MPLTEXT 1 206 0 "" } {MPLTEXT 1 206 8 "\nend do;" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 10 " \nend proc:" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 16 "twoneighbors(J);" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"%" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\")" }{TEXT 207 0 "" }}}{PARA 205 "" 0 "" {TEXT 210 0 "" }{TEXT 210 10 "\nEXERCISES" }{TEXT 211 0 "" }{TEXT 211 128 "\n1. \+ Write a procedure that takes two positive integers as arguments and re turns the number of primes between them (inclusively)." }{TEXT 211 0 " " }{TEXT 211 125 "\n2. Write a procedure that takes a positive integer as its argument and returns the smallest prime greater than that inte ger." }{TEXT 211 0 "" }{TEXT 211 115 "\n3. Write a procedure that take s a graph as its argument and returns the sum of the degrees of all of its vertices." }{TEXT 211 0 "" }{TEXT 211 179 "\n4. Write a procedure that takes a graph as its argument and displays the number of vertice s of even degree and the number of vertices of odd degree. Hint: the B oolean expression " }{TEXT 212 12 "type(n,odd) " }{TEXT 211 8 "returns " }{TEXT 213 4 "true" }{TEXT 211 4 " if " }{TEXT 213 1 "n" }{TEXT 211 12 " is odd and " }{TEXT 213 5 "false" }{TEXT 211 82 " otherwise. \+ To make your output look nice, see the tips in the following exercise. " }{TEXT 211 0 "" }{TEXT 211 268 "\n5. Write a procedure that takes a \+ graph as its argument and for each vertex prints a line such as \"The \+ neighbors of vertex d are \{a,c\}.\" Then modify your procedure so tha t it also prints the number of neighbors, as in \"The 2 neighbors of v ertex d are \{a,c\}.\" See the " }{TEXT 212 6 "printf" }{TEXT 211 265 " command in the Help menu for tips on how to create this sort of outp ut. Hint: look at the examples near the end of the Help description. T he formats (shown as %d for integer, %s for string, %a for any Maple o bject, etc.), are also listed in this same Help section." }{TEXT 211 0 "" }{TEXT 211 245 "\n6. Write a procedure that takes a graph as its \+ argument and indicates whether the graph contains a loop. Use a while \+ ... do loop rather than a for ... do loop so that once a loop is found the procedure will not do further unnecessary searching." }{TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT 214 0 "" }}{PARA 205 "" 0 "" {TEXT -1 0 "" }}}{MARK "0 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }