{VERSION 5 0 "APPLE_PPC_MAC" "5.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 "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 261 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 266 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 268 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 270 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 271 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 272 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 273 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 274 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 275 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 276 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 277 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 278 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 279 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 280 "" 1 8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 256 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 257 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 16 "Introduction to " } {TEXT 256 5 "Maple" }{TEXT -1 0 "" }}{PARA 257 "" 0 "" {TEXT -1 12 "Pr ogramming " }{TEXT 280 44 "by Bob Bradshaw, Ohlone College, Fremont, C A" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 154 "A c omputer program allows a computer to do repetitive operations without \+ having a person constantly telling the computer what to do. The simple st type of " }{TEXT 260 5 "Maple" }{TEXT -1 46 " program may consist o f only a single command." }}{PARA 0 "" 0 "" {TEXT -1 39 "For example, \+ if you wanted to find the " }{XPPEDIT 18 0 "sum(1/x,x = 1 .. n);" "6#- %$sumG6$*&\"\"\"F'%\"xG!\"\"/F(;F'%\"nG" }{TEXT -1 24 " between for v alues of " }{TEXT 257 1 "n" }{TEXT -1 62 " between 2 and 5, a person \+ would have to do the computations " }{XPPEDIT 18 0 "sum(1/x,x = 1 .. 2 );" "6#-%$sumG6$*&\"\"\"F'%\"xG!\"\"/F(;F'\"\"#" }{TEXT -1 4 " , " } {XPPEDIT 18 0 "sum(1/x,x = 1 .. 3);" "6#-%$sumG6$*&\"\"\"F'%\"xG!\"\"/ F(;F'\"\"$" }{TEXT -1 4 " , " }{XPPEDIT 18 0 "sum(1/x,x = 1 .. 4);" " 6#-%$sumG6$*&\"\"\"F'%\"xG!\"\"/F(;F'\"\"%" }{TEXT -1 7 " , and " } {XPPEDIT 18 0 "sum(1/x,x = 1 .. 5);" "6#-%$sumG6$*&\"\"\"F'%\"xG!\"\"/ F(;F'\"\"&" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "We can have " }{TEXT 258 5 "Maple" }{TEXT -1 55 " perform all these computations by using a \"for\" loop. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 75 "\nfor n from 2 to 5 do \n Sum( 1/x,x=1..n)=evalf(sum(1/x,x=1..n)) \n od;" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 47 "\nTo compute sums for non-consecutive values of " } {TEXT 259 1 "n" }{TEXT -1 19 ", use the following" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 81 "for n from 1 by 6 to 20 do \n Sum(1/x,x=1..n) =evalf(sum(1/x,x=1..n)) \n od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 113 "\nTo create a more elaborate program, we can use something called a procedure. A procedure is simply the lines of " }{TEXT 261 6 "Maple " }{TEXT -1 269 "that you would use to accomplish a task if you were \+ doing the task by yourself. For example, suppose you wanted to find th e equation of the line that passes through two points. First, you woul d determine the slope of the line and then you could use the equation \+ of the " }}{PARA 0 "" 0 "" {TEXT -1 5 "line " }{TEXT 262 1 "y" }{TEXT -1 3 " = " }{TEXT 263 1 "m" }{TEXT -1 1 "(" }{TEXT 264 1 "x" }{TEXT -1 3 " - " }{TEXT 265 1 "x" }{TEXT -1 5 "1) + " }{TEXT 266 1 "y" } {TEXT -1 47 "1. We can write a procedure to do exactly that." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 63 "In the lines th at follow, p and q are points where p[1] is the " }{TEXT 267 1 "x" } {TEXT -1 28 " value of p and p[2] is the " }{TEXT 268 1 "y" }{TEXT -1 13 " value of p. " }}{PARA 0 "" 0 "" {TEXT -1 21 "The first line tells " }{TEXT 271 5 "Maple" }{TEXT -1 62 " that you are going to give the \+ procedure two points, p and q." }}{PARA 0 "" 0 "" {TEXT -1 37 "The sec ond line of the program tells " }{TEXT 269 5 "Maple" }{TEXT -1 0 "" } {TEXT 270 1 " " }{TEXT -1 62 "that the name \"slope\" has no meaning o utside of the procedure." }}{PARA 0 "" 0 "" {TEXT -1 47 "The third and fourth lines do the calculations." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "line:=proc(p,q)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "local slope; \nslope:=(q[2]-p[2])/(q[1]-p[1]);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "y=slope*(x-p[1])+p[2];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 33 "To use the procedure, first tell " }{TEXT 272 5 "Maple" }{TEXT -1 44 " the points through which you want the line." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{MPLTEXT 1 0 18 "p:=[1,2];q:=[5,7];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 10 "Next, ask " } {TEXT 273 6 "Maple " }{TEXT -1 55 " to use the procedure to give the e quation of the line." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{MPLTEXT 1 0 10 "line(p,q);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "You can also give the points directly to the procedu re." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{MPLTEXT 1 0 18 "line([3,5],[6,7 ]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 125 "The next step is to modify the procedure to allow for the case where the slope of the line is undefined. To do this, use the " } {TEXT 274 17 "if \311 then \311 else " }{TEXT -1 8 "command." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 178 "In the line \" if q[1] - p[1] <> 0\", the procedure first asks if the denominator of \+ the slope is not equal to zero. If this is true, the procedure returns the equation of the line." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 99 "If the denominator does equal zero, the slope is undefined and the equation of the line is in the " }}{PARA 0 "" 0 "" {TEXT -1 5 "form " }{TEXT 275 1 "x" }{TEXT -1 8 " = p[1]." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } {MPLTEXT 1 0 16 "line2:=proc(p,q)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 121 "local slope;\n if (q[1]-p[1])<>0 then\n slope:=(q[2]-p[2])/( q[1]-p[1]);\n y=slope*(x-p[1])+p[2];\n else\n x=p[1]" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " fi;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 71 "We can now ask for the equation of the line through two points. If the " }{TEXT 276 1 "x" }{TEXT -1 90 " values are different , the procedure returns the same result as would the first procedure. " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "line2([3,4],[10,11]);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 72 "If we ask for the equation of the line through two points with the same \+ " }{TEXT 278 2 "x " }{TEXT -1 64 "values, the procedure returns the eq uation fo the vertical line." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "lin e2([2,9],[2,11]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 274 "The next version of the procedure is more elabora te. Instead of simply giving the equation of the line through the poin ts, the procedure creates a graph of the points and the line through t he points. The program then uses the equation of the line as the title of the graph. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 37 "Before starting the program, restart " }{TEXT 277 5 "Mapl e" }{TEXT -1 14 " and load the " }{TEXT 279 5 "plots" }{TEXT -1 11 " s ubroutine" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "restart;with(plots):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 96 "The program below looks complicated but simply finds the equation of \+ the line and draws a graph." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } {MPLTEXT 1 0 16 "line3:=proc(p,q)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 604 "local slope,y,Title,Line,Points;\n\nif (q[1]-p[1])<>0 then\nslope :=(q[2]-p[2])/(q[1]-p[1]);\ny:=slope*(x-p[1])+p[2];\nTitle:=cat(\"y = \+ \",convert(y,string)); Line:=plot(slope*(x-p[1])+p[2],x=min(p[1],q [1])-4..max(p[1],q[1])+4,color=blue,title=Title,titlefont=[HELVETICA,B OLD,24]);\nPoints:=plot(\{p,q\},style=point,symbol=circle,color=red,ax es=normal);\ndisplay(Line,Points);\n\nelse\nTitle:=textplot([p[1],max( p[2],q[2])+3,cat(\"x = \",convert(p[1],string))],font=[HELVETICA,BOLD, 24]);\nLine:=plottools[line](p,q,color=blue);\nPoints:=plot(\{p,q\},st yle=point,symbol=circle,color=red);\ndisplay(\{Line,Points,Title\});\n fi;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "line3([8,5],[6,9]);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 21 "line3([2,5],[2,-25]);" }}}}{MARK "0 1 1" 44 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }