{VERSION 2 3 "APPLE_PPC_MAC" "2.3" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Geneva" 1 10 0 0 0 1 2 2 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plot" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 } {PSTYLE "R3 Font 0" -1 256 1 {CSTYLE "" -1 -1 "Monaco" 1 9 0 0 255 1 2 2 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "R3 Font 0 " -1 257 1 {CSTYLE "" -1 -1 "Geneva" 1 12 0 0 0 1 2 2 2 0 0 0 0 0 0 } 0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "R3 Font 2" -1 258 1 {CSTYLE "" -1 -1 "Geneva" 1 10 0 0 0 1 2 2 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 257 "" 0 "" {TEXT -1 766 "FUNCTION: HTSimulation \nCALLING SEQUENCE: HTSimulation(n, m, show)\nPARAMETERS: \n n, \+ m - integers\n show - a string\n SYNOPSIS:\n - This program s imulates an experiment in which a fair coin is tossed m times. \n \+ The experiment is repeated n times. The program records the \"winn ings\" in each\n experiment, where the winnings are defined to \+ be the number of heads minus\n the number of tails. It also ke eps track of the number of times the winnings are\n \"positive \" in the course of an experiment (we count as \"positive\" a time at \+ which\n the winnings are 0, but the previous winnings are posit ive). The third variable in the \011\011 program call, \+ show, allows the user to select one of four options for displaying " } }{PARA 257 "" 0 "" {TEXT -1 91 " the output \011of the experime nts. If show = lists, the program returns a list whose " }}{PARA 257 "" 0 "" {TEXT -1 87 " first element is a\011list (winningslist) of the winnings in each experiment, and " }}{PARA 257 "" 0 "" {TEXT -1 201 " whose second element is a list (timesinleadlist) of ti mes in the lead in each experiment. T o output the results of any single game (n=1), let show\011=onegame, \+ " }}{PARA 257 "" 0 "" {TEXT -1 92 " and a graph of the result s will be displayed. \011\011With multiple games (n>1), one can " }} {PARA 257 "" 0 "" {TEXT -1 82 " view either a spikegraph of win ningslist or of timesinleadlist by letting " }}{PARA 257 "" 0 "" {TEXT -1 501 " show = plotwins or show = plotleads, respectivel y. \n - Note: this program requires the programs \"SpikeData(dat a)\" and \011\011\011\011\011\011 \+ \"Spikegraph(distributionlist, xmin,xmax, show)\" be initialized .\nRETURNED VALUES:\n - a list whose first element is a list of t he winnings in each experiment, and whose\n second element is a list of times in the lead in each experiment\nLOCATION:\n Folder: Chapter 1\n File: \"HTSimulation.Chpt1.map\"\n\n" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 1028 "HTSimulation:=proc(n,m,show)\n\011local i ,j,winnings,leads,lastwin,winningslist,timesinleadlist,pointlist,\n \011\011\011mn,mx:\n\011winningslist:=[]: timesinleadlist:=[]: point list:=[0,0]:\n\011for i from 1 to n do\n\011\011winnings:=0:\n\011\011 leads:=0:\n\011\011for j from 1 to m do\n\011\011\011lastwin:=winnings :\n\011\011\011if (rand()*(10^(-12)))>=.5 \n\011\011\011\011then winni ngs:=winnings+1:\n\011\011\011\011else winnings:=winnings-1:\n\011\011 \011fi:\n\011\011\011if (winnings>0) or ((winnings=0) and (lastwin>0)) then\n\011\011\011\011leads:=leads+1:\n\011\011\011fi:\n\011\011\011i f show=onegame then\n\011\011\011\011pointlist:=[op(pointlist),j,winni ngs]:\n\011\011\011fi:\n\011\011od:\n\011\011winningslist:=[op(winning slist),winnings]:\n\011\011timesinleadlist:=[op(timesinleadlist),leads ]:\n\011od:\n\011if show=onegame\n\011\011then plot(pointlist,style=LI NE);\n\011elif show=plotwins then\n\011\011mn:=min(op(winningslist)): \+ mx:=max(op(winningslist)):\n\011\011Spikegraph(SpikeData(winningslist ),mn,mx,true);\n\011elif show=plotleads then\n\011\011mn:=min(op(times inleadlist)): mx:=max(op(timesinleadlist)):\n\011\011Spikegraph(Spike Data(timesinleadlist),mn,mx,true);\n\011elif show=lists then\n\011\011 RETURN(winningslist,timesinleadlist);\n\011fi; \nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "HTSimulation(10,100,lists);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6$7,\"#7\"\")!#5F&!\"%\"#;!\")F%F%!#77, \"#'*F,\"#9\"\"#\"#OF,F.\"$+\"\"#U\"#_" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "HTSimulation(1000,40,plotleads);" }}{PARA 13 "" 1 "" {INLPLOT "6$-%'CURVESG6$7[o7$\"\"!F(7$F($\"1++++++g6!#;F'7$$\"\"#F(F(7 $F.$\"1,++++++p!#