{VERSION 4 0 "APPLE_PPC_MAC" "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 "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 35 "" 0 1 104 64 92 1 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 268 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 270 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 271 "" 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 394 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 395 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 396 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 397 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 398 "" 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 399 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 } {CSTYLE "" -1 400 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 401 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 402 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Tim es" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "T imes" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Normal" -1 256 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 257 1 {CSTYLE "" -1 -1 "Times" 1 12 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 258 1 {CSTYLE "" -1 -1 "T imes" 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 259 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT 256 9 "Lecture 4" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 33 " Deletion and Undoing a Deletion." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 151 "Usually \+ selecting something with the cursor and hitting the delete key will de lete things. But to delete some things I have found that I need to u se " }{TEXT 333 6 "Delete" }{TEXT -1 1 " " }{TEXT 334 9 "Paragraph" } {TEXT -1 20 " from the pull down " }{TEXT 335 4 "Edit" }{TEXT -1 73 " \+ menu. Then the paragraph where your cursor is located will be deleted. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "Af ter deleting or pasting something, if you change your mind before doi ng anything else, you can go to the top of the " }{TEXT 336 4 "Edit" }{TEXT -1 10 " menu and " }{TEXT 337 4 "undo" }{TEXT -1 23 " the delet ion or paste." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 239 "Also note that if you click the paragraph symbol at the \+ right end of the menu bar it will sometimes help to see what you shoul d delete. This is especially true when dealing with text. To get back \+ to normal click the paragraph symbol again." }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 32 " Pseudo Random \+ Number Generators" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 " " 0 "" {TEXT 315 10 "rand(a..b)" }{TEXT -1 49 " is a procedure with no arguments that creates a " }{TEXT 317 23 "(pseudo) random integer" } {TEXT -1 13 " in the range" }{TEXT 316 8 " a to b." }{TEXT -1 233 " To call the procedure one needs to add extra parenthensizes as in the fo llowing examples. If you don't add the extra () after rand(a..b) you j ust get the description of the procedure. We will use the custom of ca lling the output of " }{TEXT 397 12 "rand(a..b)()" }{TEXT -1 3 " a " } {TEXT 322 13 "random number" }{TEXT -1 214 ". But strictly speaking th e numbers so give are not really random. After all, they are generat e by a compute program. If you wish to learn more about such matters I recommend that you take a look at the book The " }{TEXT 318 27 "Art o f Computer Programming" }{TEXT -1 1 " " }{TEXT 319 30 "Vol 2 Seminumer ical Algorithms" }{TEXT -1 38 ", by Donald Knuth. See Chapter Three \+ " }{TEXT 320 14 "Random Numbers" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "rand(0..20)();" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 127 "If you want to use this procedure repeatedly you can give it a sh orter name. I will use f here. Sometime people use names like " } {TEXT 338 4 "dice" }{TEXT -1 4 " or " }{TEXT 339 3 "die" }{TEXT -1 14 " (singular of " }{TEXT 340 4 "dice" }{TEXT -1 3 "), " }{TEXT 343 4 "r oll" }{TEXT -1 6 ", or " }{TEXT 341 4 "flip" }{TEXT -1 37 ". But you \+ can use any name you wish. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "f:=rand(0..20):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 20 "Note that \+ each time " }{TEXT 321 4 "f ()" }{TEXT -1 56 " is executed it gives a \+ usually different random number." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "for i from 1 to 4 do print(i,f()); od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "Or, we can create a sequence of 50 random numbers as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "seq (f(), i=1..50);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 37 "Let's create a sequence of 50 random " }{TEXT 342 4 "bits" }{TEXT -1 14 " ( 0s and 1 s):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "b:=rand(0..1):\nseq( b(), i=0..50);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 82 "To get a (pseudo) random number in the interval [0,1 ] you might use the following:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "h:=rand(0..10^6):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "for i from 1 to 10 do\nprint (evalf(h()/10^6));\nod;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 " " }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 30 " Generating Pseudo Random S ets" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 25 "Here's one way to pick a " }{TEXT 311 22 "(pseudo) random subset" }{TEXT -1 26 " from the set \{1 ,2,3,4,5\}:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "with(combina t); #first load the package combinat" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "n:=5;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "S: =powerset(\{seq(i,i=1..n)\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(S);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "f:=rand(1. .nops(S)):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 259 "\nThere are 2^5 = \+ 32 subsets of \{1,2,3,4,5\}. The set S above contains these 32 sets. I f we use f as just defined to get a random number i from 1 to 32. Then the corresponding set S[i] may be considered as a random subset of \{ 1,2,3,4,5\}. Here are some examples:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S[f()];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S[f()];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S[f()];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 91 "A bett er way to generate a random set is given in the homework assignment fo r this lecture." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 24 " The procedu re numboccur" }}{PARA 0 "" 0 "" {TEXT -1 14 "The procedure " }{TEXT 312 9 "numboccur" }{TEXT -1 150 " can be used to simplify the type of \+ computation made in the last lecture when counting the number of times a digit appears in the first n digits of " }{XPPEDIT 18 0 "pi;" "6#% #piG" }{TEXT -1 7 ". The " }{TEXT 35 15 "numboccur(f, x)" }{TEXT -1 43 " function returns the number of times that " }{TEXT 35 1 "x" } {TEXT -1 13 " is found in " }{TEXT 35 3 "f, " }{TEXT 313 29 "where f m ay be any expression" }{TEXT 314 2 ". " }{TEXT -1 23 "Here are some ex amples:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "roll:=rand(1..6): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "L:=[seq(roll(),i=1..100 )];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "numboccur(L,2);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "for i from 1 to 6 do\n i,n umboccur(L,i);\nend do;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "p:=x^3+3*x*y+2*x^2 + 5*x + 1;\nnumboccur(p,x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "A:=matrix([[1,2,3],[1,3,6]]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "Note that numboccur doesn't work with mat rices unless we use first the function " }{TEXT 344 5 "evalm" }{TEXT -1 31 ", as in the following examples:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "numboccur(A,3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "numboccur(evalm(A),3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 20 " Remarks on Packages" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(linalg);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 258 6 "linalg" }{TEXT -1 34 " is an example of what are called \+ " }{TEXT 259 8 "packages" }{TEXT -1 126 " in Maple. A package is a col lection of commands that must be loaded before they can be used. Othe r examples of packages are " }{TEXT 260 56 "numtheory, combinat, group s, logic, geometry, finance, " }{TEXT -1 4 "and " }{TEXT 261 6 "plots ." }{TEXT -1 47 " To see a list of all packages use the command " } {TEXT 262 14 "?index,package" }{TEXT -1 1 "." }{TEXT 263 1 " " }{TEXT -1 34 "To load a package use the command " }{TEXT 257 4 "with" }{TEXT -1 69 " as in the above example: Note that if you use a semicolon afte r the " }{TEXT 264 12 "with(linalg)" }{TEXT -1 133 " command you will \+ get a list of all the commands in that package. If you don't want to s ee all the commands, just use a colon. \n\n[In " }{TEXT 275 7 "Maple 6 " }{TEXT -1 52 " there are a number of new packages that are not in " }{TEXT 276 7 "Maple V" }{TEXT -1 36 ". For example, there is the packa ge " }{TEXT 265 13 "LinearAlgebra" }{TEXT -1 29 " -- but Maple 6 also \+ retains " }{TEXT 266 6 "linalg" }{TEXT -1 10 ". The new " }{TEXT 267 13 "LinearAlgebra" }{TEXT -1 54 " package in Maple 6 has a lot of the \+ same features as " }{TEXT 268 6 "linalg" }{TEXT -1 62 " but it has add itional commands for creating special types of " }{TEXT 269 8 "Matrice s" }{TEXT -1 101 ", and improved Matrix algebra. Also, especially when calculating with large numeric (floating point) " }{TEXT 270 8 "Matri ces" }{TEXT -1 150 ", it is much more powerful and efficient. Note th at the new commands in LinearAlgebra are genrally capitalized unlike i n the package linalg. So that " }{TEXT 271 6 "matrix" }{TEXT -1 5 " an d " }{TEXT 272 6 "Matrix" }{TEXT -1 63 " are different data type. To \+ simplify matters I will stick to " }{TEXT 273 6 "linalg" }{TEXT -1 17 " in this course. " }{TEXT 345 92 "If you need to do calculations with large numeric matrices you should look into the package " }{TEXT 274 13 "LinearAlgebra" }{TEXT 346 1 "." }{TEXT -1 1 "]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "?index,package" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 20 "with(LinearAlgebra);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 20 " Arrays and Matrices" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 18 "Before discussing " }{TEXT 277 6 "matrix" }{TEXT -1 40 " let's dis cuss the more general concept " }{TEXT 278 5 "array" }{TEXT -1 40 ": M ore details can be obtained by use of" }{TEXT 279 9 " ?array. " } {TEXT -1 136 "They are best understood by looking at examples: Arrays \+ are one type of indexed variable. The subscripts each must run thru a \+ specified " }{TEXT 280 5 "range" }{TEXT 398 1 " " }{TEXT 399 12 " of i ntegers" }{TEXT -1 107 ": Arrays come in different dimensions: 1-dimen sional, 2-dimensional, 3-dimensional, etc. Here are examples:" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "A:=array(-3..4);\n" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 114 "The array A has indices -3, -2, - 1, 0, 1, 2, 3, 4. A is a 1-dimensional array. We may assign values a s follows:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "for i from \+ -3 to 4 do A[i]:=i^2; end do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 " Note that you cannot use other values for the index of A:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "A[5]:=2;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 77 "Now we define a 2-dimentional array B. Again we specify t he range of indices." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "B:= array(-1..2,0..1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "Here we ass ign values to the array:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "for i from -1 to 2 do \nfor j from 0 to 1 do \n B[i,j]:=i + j*x;\nend do;\nend do;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(B);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 9 "B[1,-1]; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "B[-1,0];" }}}{PARA 0 "" 0 "" {TEXT -1 2 "A " }{TEXT 281 6 "matrix" }{TEXT -1 153 " is a 2-dimensional array where the row \+ and column indices start with 1. One can define matrices directly or c onvert a 2-dimensional array into a matirx." }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 22 "MB:=convert(B,matrix);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 34 "B[-1,0],B[-1,1]; \nMB[1,1],MB[1,2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "MB;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "evalm(MB);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "C:=array(1..4,1..2);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "for i from 1 to 4 do\nfor j \+ from 1 to 2 do\n C[i,j]:=(i-2)+(j-1)*x; \nod;\nod;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "type(B,matrix);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type( B,array);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "type(MA2, ma trix);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type(C,matrix);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "L:=[ [1,2],[0,1],[1,2],[4 ,5]];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 74 "Note that the following \+ all give the same result, namely, a 4 by 2 matrix." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "X:=array(1..4,1..2, L);\nY:=array(L);\nZ:=m atrix(L);\nW:=matrix(4,2,[1,2,0,1,1,2,4,5]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "ty pe(X,matrix), type(Y,matrix), type(Z,matrix), type(W,matrix);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 88 "If you just specify the dimensions of the matrix you may treat the entries as variables." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "H:=matrix(2,2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "H;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalm(H);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 86 "To change one o f the entries uses an assignment statement as in the following example :" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "H[1,2]:=10000;\nevalm( H);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 7 " Tables" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 28 "We now discuss the datatype " }{TEXT 282 5 "table" }{TEXT -1 36 ". Table s are similar to arrays, but " }{TEXT 287 93 "the indices need not be \+ integers and one need not declare that a variable represents a table. " }{TEXT -1 171 " If you make an assignment of the form G[z]:=w, then \+ Maple creates a table with the entry z=w. Then you may add to this ta ble at will. You may also use tables to create " }{TEXT 288 17 "index ed variables" }{TEXT -1 88 ". In fact indexed variables are just tabl es. We illustrate by creating a table named G:" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "G[z]:=w;\nG[box]:=red;\nfor i from 1 to 5 do G[i]:=\{0,i,i+1\} ; od;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "G[z]; G[box];G[1]; G[2]; G[3];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "G;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(G);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 29 "type(G,table);\ntype(G,array);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "cat(E,d,w,'i',n); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "for i in \{p,q,r\} do G[i]:=cat(i,s tuff); od;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(G);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "G[r];\nG[box];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 39 "Here's how you can get a list of the i" }{TEXT 283 7 "ndices " }{TEXT -1 29 "of a table and a list of the " } {TEXT 284 7 "entries" }{TEXT -1 84 " in the table. Note that the indic es and entries are exhibited as one element lists." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "entries(G);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 8 "On e can " }{TEXT 286 6 "change" }{TEXT -1 25 " the entries in an array: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "G[1]:=G[1] union \{infinity\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 8 "One can " }{TEXT 285 6 "delete" }{TEXT -1 54 " indice s and entries as in the following two examples." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 30 "G[1];\nG[1]:=evaln(G[1]);\nG[1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 25 "G[2];\nG[2]:='G[2]';\nG[2];" }}{PARA 0 "" 0 " " {TEXT -1 42 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 176 "Note that we do not have to declare before hand tha t a variable is going to represent a table. However, we must do so for arrays and matrices: Consider the following examples:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 62 "for i from 1 to 2 do\nfor j from 1 to 2 do\nZ[i,j]: =i+j;\nod;\nod;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "type(Z,t able), type(Z,array);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eva l(Z);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "But look what happens if we first say that Z is an array:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 92 "restart:\nZ:=array(1..2,1..2);\nfor i from 1 to 2 do \nfor j from 1 to 2 do\nZ[i,j]:=i+j;\nod;\nod;" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 44 "type(Z,table),type(Z,array), type(Z,matrix);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(Z);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 20 " Functions vs Tables" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 289 10 "Functions:" } {TEXT -1 94 " We have already seen three ways to make functions from e xpressions.\nHere we show another way:" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 256 "" 0 "" {TEXT 293 13 "First we can " }{TEXT -1 22 "assig n values at will " }{TEXT 294 60 "as follows: We make up a couple of f unctions called f and g." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 " restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "f(1):=2; f(2):= 3; f(3):=1;\ng(1):=2; g(2):=1; g(3):=3;" }}}{EXCHG {PARA 257 "" 0 "" {TEXT -1 82 "This explains why f(x):=x^2+1; does not define f. Actuall y it defines the function" }}{PARA 0 "" 0 "" {TEXT 301 64 "f at the va riable x only, but not for anything different from x." }{TEXT -1 13 " \+ For example:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "h(x):=x^2+x +1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "h(x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "h(y);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "This indicates that you have not yet defined h at the val ue y." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 290 24 "Composition of functions" }{TEXT -1 53 " in Maple is \+ given by @: For example, the composition" }}{PARA 0 "" 0 "" {TEXT -1 81 "of f and g as defined above is f@g. Also the composition of f with itself n times" }}{PARA 0 "" 0 "" {TEXT -1 17 "is given by f@@n:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "(f@g)(1), f(g(1)); " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "(f@@3)(1), f(f(f(1)));" }}} {EXCHG {PARA 256 "" 0 "" {TEXT 291 15 "Second, we can " }{TEXT -1 33 " change the value of any function " }{TEXT 292 34 "whether we made it, \+ or it is built" }}{PARA 0 "" 0 "" {TEXT -1 42 "into Maple: (Not someth ing to do lightly.)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "sin( 0):=3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "sin(0);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "sin(0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 298 9 "Functions" }{TEXT -1 8 " versus " }{TEXT 299 6 "tables" }{TEXT -1 25 ": Expression of the form " }{TEXT 300 14 "name(variable)" } {TEXT -1 13 " are of type " }{TEXT 295 8 "function" }{TEXT -1 50 ". On the other hand if your execute the statement " }{TEXT 296 22 "name[va riable]:=value;" }{TEXT -1 17 " then Maple give " }{TEXT 347 4 "name" }{TEXT -1 10 " the type " }{TEXT 297 5 "table" }{TEXT -1 41 ". This gi ves us the peculiar result that " }{TEXT 302 6 "sin(x)" }{TEXT -1 6 " \+ is a " }{TEXT 303 17 "function in Maple" }{TEXT -1 6 ", but " }{TEXT 304 3 "sin" }{TEXT -1 4 " is " }{TEXT 305 23 "not a function in Maple " }{TEXT -1 2 ". " }{TEXT 306 9 "NOTE WELL" }{TEXT -1 107 ": This usag e deviates from the usual mathematical meaning of function. In ordinar y mathematics we say that " }{TEXT 307 3 "sin" }{TEXT -1 19 " is a fun ction and " }{TEXT 308 6 "sin(x)" }{TEXT -1 17 " is the value of " } {TEXT 309 3 "sin" }{TEXT -1 14 " at the value " }{TEXT 310 1 "x" } {TEXT -1 234 ". In certain constructions, for example when solving rec urrences and differential equations one is required to use the Maple n otion of a function. The reason is that in these cases Maple needs to \+ know what the independent variable is." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "restart;\ntype(f(x),function);\n\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "type(sin,function);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "type(sin(x),function);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 20 "type(sin,procedure);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "type(g,table);\ng[x]:=y;\ntype(g,table);" }} {PARA 11 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 348 8 " whattype" }{TEXT -1 89 " will give the type, but sometimes one needs t o use eval first, as in the examples below:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(sin);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "whattype(eval(sin));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "g[3]:=3: \nwhattype(g);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "whattype(eval(g));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "whattype(f(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(.34);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(3/4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "w hattype(-3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(3) ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type(3,posint);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "whattype((x+z)*(y+3));" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 " " {TEXT -1 35 " Introduction to the linalg package" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "There are lots of \+ things one can do with matrices after the " }{TEXT 361 6 "linalg" } {TEXT -1 21 " package is loaded as" }}{PARA 0 "" 0 "" {TEXT -1 73 "we \+ did above. If the matrices are not too big maple will easily compute \+ " }{TEXT 365 12 "determinants" }{TEXT -1 1 "," }}{PARA 0 "" 0 "" {TEXT -1 5 "find " }{TEXT 362 11 "eigenvalues" }{TEXT -1 2 ", " } {TEXT 363 12 "eigenvectors" }{TEXT -1 2 ", " }{TEXT 364 22 "Jordan Can onical Forms" }{TEXT -1 41 ", etc.... Here are a few simple examples: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(linalg):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "M:=randmatrix(2,2);\nA:=randmatrix(2,2,symmet ric);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "B:=randmatrix(2, 2);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "multiply(A,B);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "inverse(A);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "det(A);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "eigenvals(A);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "EV:=eigenvects(A);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "EV[1];" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "a1 is the first eigenvalue:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "a1:=EV[1][1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "EV[1][2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "EV[1][3] ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "v1 is an eigenvector corres ponding to the eigenvalue a1." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "v1:=EV[1][3][1];" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "We now check that Av1 = a1*v1:" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "multiply(A,v1); \nmap(expan d, evalm(a1*v1));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A+B^2; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalm(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "Id:=array(identity, 1..4,1..4);\nev alm(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 9 " Vectors " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 2 "A " }{TEXT 323 7 "vector " }{TEXT -1 10 "is just a " }{TEXT 400 46 "1-dimensional arrary with index beginning at 1" }{TEXT -1 36 ". It may be formed with the command " }{TEXT 326 15 "vector(lis t) , " }{TEXT -1 12 "the command " }{TEXT 324 11 "array(list)" }{TEXT -1 17 ", or the command " }{TEXT 325 26 "array(1..n,list). Vectors" } {TEXT -1 73 " have some seemingly strange properties. When printed out they look like " }{TEXT 327 4 "list" }{TEXT -1 4 " or " }{TEXT 328 8 "matrices" }{TEXT -1 222 ", but they behave differently in some cases. Maple treats them as column vectors for many purposes. I suggest avoi ding them except when necessary in linear algebra problems. We will sp end more time on linear algebra later." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(linalg):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "L:=[1,2,3 ]; " }{TEXT -1 46 "#this is a list, not a vector, matrix or array" } {MPLTEXT 1 0 23 "\n\nv1:=vector([1,2,3]); " }{TEXT -1 55 "#this is a v ector and an array but not a list or matrix" }{MPLTEXT 1 0 22 "\nv2:=a rray([1,2,3]); " }{TEXT -1 55 "#this is a vector and an array but not a list or matrix" }{MPLTEXT 1 0 24 "\n\na1:=array([[1,2,3]]); " } {TEXT -1 74 "#this is an array and a 1 by 3 matrix, but is not a list \+ and not a vector," }{MPLTEXT 1 0 23 "\nm1:=matrix([[1,2,3]]);" }{TEXT -1 74 "#this is an arrary and a 1 by 3 matrix but is not a list and no t a vector." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 168 "Note that the 1 b y 3 matrices look different from vectors and lists when printed out. O n the other hand one cannot distinguish lists from vectors when they a re printed." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "a1[1];" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 70 "The matrices are 1 by 3 and so we \+ need 2 indices to specify elements. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "a1[1,1],a1[1,2],a1[1,3];" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 33 " Multiplying a vector by a matrix" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 355 "R ecall that if A is an n by k matrix and B is an m by t matrix then the product AB is defined if and only if k = m. Maple uses this same rule . However if A is an n by k matrix and v is a vector of length k then Maple computes the product as if v was a k by 1 matrix -- even though when printed v looks more like a 1 by k matrix. Here are some example s: " }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "restart:\nwith(linalg):\n" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 30 "A:=matrix([[1,2,3], [4,5,6]]);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 37 "B:=matrix([[1,2,3],[2,3,4],[3,4,5]]);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "multiply(A,B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "multiply(B,A);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 19 "v:=vector([1,2,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "evalm(v + v), evalm(x*v);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 18 "v2:=multiply(A,v);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 98 "Lists are also sometimes treated like vectors. But note t hat a matrix times a list gives a vector." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 11 "L:=[1,2,3];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "L2:=multiply(A,L);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "type(L2,list);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "type( L,list);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "type(L2,vector) ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "L3:=convert(L2,list); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 298 "But in some respects lists a nd vectors are not interchangeable. For example, one can plot a list o f length two as a point, but a vector of length 2 will not be accepted by the plot command. Consider the following attempt to plot the vecto r L2. But after converting it to the list L3 we can plot it." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "plot([L2], style = point, sy mbol=circle);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "plot([L3], style = point, symbol = circle);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 40 " Assignment 4 Due Next Monday.. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 332 10 "Problem 1." }{TEXT -1 48 " Generate 10 random 3 by 3 matrice s using the " }{TEXT 366 10 "randmatrix" }{TEXT -1 18 " command from t he " }{TEXT 367 6 "linalg" }{TEXT -1 42 " package. As each matrix is g enerated use " }{TEXT 368 9 "eigenvals" }{TEXT -1 159 " to compute its eigenvalues. Then take the product of the eigenvalues and check that for each matrix this product is equal to the determinant of the matri x. " }{TEXT 371 6 "Hint: " }{TEXT -1 79 "The product will be complica ted algebraically and you will need to apply first " }{TEXT 369 6 "exp and" }{TEXT -1 7 ", then " }{TEXT 370 8 "simplify" }{TEXT -1 60 " to r educe the product of the eigenvalues to an integer.\n \n" }{TEXT 329 9 "Problem 2" }{TEXT -1 59 ". There is a one-to-one correspondence be tween subsets of " }{TEXT 379 17 "\{1, 2, . . . , n\}" }{TEXT -1 28 " \+ and binary lists of length " }{TEXT 386 1 "n" }{TEXT -1 17 ", that is, lists " }{TEXT 383 3 "L =" }{TEXT -1 1 " " }{TEXT 380 22 "[x1, x2 , . . . , xn] " }{TEXT -1 6 "where " }{TEXT 381 18 "x1, x2, . . . , xn" } {TEXT -1 25 " are elements of the set " }{TEXT 382 5 "\{0,1\}" }{TEXT -1 57 ". The correspondence is given by associating to the set " } {TEXT 401 1 "S" }{TEXT -1 10 " the list " }{TEXT 385 1 "L" }{TEXT -1 7 " where " }{TEXT 384 35 "xi = 1 if i is in X and 0 if not. \n" } {TEXT -1 23 "\n(a) Write a procedure " }{TEXT 351 12 "list_to_set " } {TEXT -1 95 "whose input is a binary list and whose output is the corr esponding set.\n\n(b) Write a procedure " }{TEXT 352 11 "set_to_list" }{TEXT -1 22 " whose input is a pair" }{TEXT 372 4 " S,n" }{TEXT -1 7 " where " }{TEXT 373 1 "S" }{TEXT -1 16 " is a subset of " }{TEXT 374 17 "\{1, 2, . . . , n\}" }{TEXT -1 5 " and " }{TEXT 377 1 "n" }{TEXT -1 69 " is a positive integer and whose output is the binary list of l ength " }{TEXT 376 1 "n" }{TEXT -1 26 " corresponding to the set " } {TEXT 375 1 "S" }{TEXT -1 68 ". \n\n(c) Show by a few tests that each procedure works. Then apply " }{TEXT 353 11 "set_to_list" }{TEXT -1 32 " to each set in the powerset of " }{TEXT 378 12 "\{1, 2, 3, 4\}" } {TEXT -1 170 " to form all binary lists of length 4. Make a program to print out a table of the following form\n\n [0,0,0,0] <--> \{ \} \n [1,0,0 0] <--> \{ 1 \}\n [0,1,0,0] <--> \{ 2 \} " }}{PARA 0 "" 0 "" {TEXT -1 12 " ........" }}{PARA 0 "" 0 "" {TEXT -1 7 " etc " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 40 "Some \+ extra commas in the output is okay." }}{PARA 0 "" 0 "" {TEXT -1 1 "\n " }{TEXT 330 11 "Problem 3." }{TEXT -1 14 " Note that if " }{TEXT 393 1 "n" }{TEXT -1 20 " is an integer then " }{TEXT 387 18 "convert(n ,base, 2)" }{TEXT -1 14 " will convert " }{TEXT 394 1 "n" }{TEXT -1 86 " to a binary list (the binary representation of n in reverse order ). Then you may use " }{TEXT 354 11 "list_to_set" }{TEXT -1 46 " to co nvert this list to a set. Note that if " }{TEXT 395 1 "n" }{TEXT -1 11 " runs from " }{TEXT 396 1 "0" }{TEXT -1 4 " to " }{XPPEDIT 18 0 "2 ^n-1;" "6#,&)\"\"#%\"nG\"\"\"F'!\"\"" }{TEXT -1 6 " then " }{TEXT 358 32 "list_to_set(convert(n,base,2) ) " }{TEXT -1 25 "will give all subs ets of " }{TEXT 388 16 "\{1, 2, . . ., n\}" }{TEXT -1 42 ". \n\n(a) Us e this idea to make a procedure " }{TEXT 357 9 "PowerSet " }{TEXT -1 43 "which will given n produce the powerset of " }{TEXT 389 17 "\{1, 2 , . . . , n\}" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 93 "Show by \+ a several examples that your procedure works.\n\n(b) Use this idea to \+ make a procedure " }{TEXT 356 7 "RandSet" }{TEXT -1 43 " which given n produces a random subset of " }{TEXT 390 17 "\{1, 2, . . . , n\}" } {TEXT -1 2 ".\n" }{TEXT 392 1 "[" }{TEXT -1 4 "Use " }{TEXT 402 4 "ran d" }{TEXT -1 89 " to produce a random integer in the appropriate range and then convert it to a subset of " }{TEXT 391 17 "\{1, 2, . . . , n \}" }{TEXT -1 1 "." }{TEXT 355 2 "]\n" }{TEXT -1 49 "Show by a few exa mples that your procedure works." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 1 "\n" }{TEXT 331 9 "Problem 4" }{TEXT -1 108 ". Construct an original example of each of the following types of Maple expressions. Check ea ch using both " }{TEXT 349 4 "type" }{TEXT -1 5 " and " }{TEXT 350 10 "whattype. " }{TEXT -1 25 "Note that in the case of " }{TEXT 359 8 "whattype" }{TEXT -1 21 " you may need to use " }{TEXT 360 4 "eval" } {TEXT -1 32 " as illustrated in the lecture. " }}{PARA 256 "" 0 "" {TEXT -1 0 "" }}{PARA 256 "" 0 "" {TEXT -1 8 "list\nset" }}{PARA 256 " " 0 "" {TEXT -1 12 "array\nmatrix" }}{PARA 256 "" 0 "" {TEXT -1 6 "vec tor" }}{PARA 256 "" 0 "" {TEXT -1 23 "table\ninteger\nprocedure" }} {PARA 256 "" 0 "" {TEXT -1 8 "function" }}{PARA 256 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 2 "\n\n" }}}}{MARK "12" 0 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 1 1 2 33 1 1 }