#Please do NOT post homework #Jeton Hida, September 27 2021, Assignment 7 read "/Users/jeton/Desktop/Math 336/M7.txt" > Help7() GR(p,i,N), GRt(p,i,N), GRm(N,p), OneStepMarkov(P,i), MarkovTrip(P,K), StSa(P,K) , StS(P), StSp(P,K), RandSM(N) > #Question 1 print(GRt) proc (p, i, N) local X, x, d, c; X := Statistics:-RandomVariable(Bernoulli(p))\ ; c := 0; x := i; while 0 < x and x < N do c := c+1; d := trunc(Statistics:-\ Sample(X, 1)[1]); if d = 0 then x := x-1 else x := x+1 end if end do; if x = 0 then RETURN([0, c]) elif x = N then RETURN([1, c]) end if end proc > EstGRt:=proc(p,y,N,K): local L: L:=add(GRt(p,y,N),i=1..K): RETURN > ([evalf(L[1]/K), trunc(evalf(L[2]/K))]): > end proc > #L[1]/K = probability of winning, L[2]/K = average number of rounds > EstGRt(0.30,5,10,1000) [0.01700000000, 12] > #Question 2 #a. The linear homogenous eq Xn(i)=1/2*(Xn(i-1)+Xn(i+1)) is true, > because from your current amount of money you have there is both a 50% chacne > to have a dollar less or have a dollar more, since the game is fair. The bound > conditions of Xn(0)=0 and Xn(N)=0 also make sense because once you have 0 > dollars left you can no longer play the game also if you get the max capital N > you have won the game! #b. Yn(i)=i/N satisifies the same recurrence because > Yn(i)=.5(i-1/N +i+1/N) = .5(2i/N) = i/N the solution works. Just like in the > original equation. the bound conditions also work because when i=0, i/N=0, and > when i=N, i/N=1. Cannot move from these positions. Makes sense because the > probability you win in a fair game depends on how much money you start out > with. #c.En(i) = 1/2(En(i-1) + En(i+1)) + 1, the expected number of rounds is > equal to the probability of winning (1/2) times the expected value of having > i-1 or i+1, the standalone +! is there because if the max amount was n+1 and > you start at n and the min amount was n-1 and you start at n there will on be > 1 move till the end of the game. The bound conditions make sense En(0)=0, and > E(N)=0. If you start at the minimum or maximum value there are no more moves > to make, the game is over. #d. Zn(i)=i(N-i) -> i(N-i)=.5(i-1(N-(i-1))+i+1(N-(i+1)))+1 -> .5(Ni-i^2+i-N+i-1+Ni-i^2-i+N-i-1)+1 -> .5(2Ni-2i^2-2)+1 -> Ni-i^2-1+1 -> Ni-i^2 -> i(N-i) if i = 0, 0(N-0)=0, i=N N(N-N)=0. The expected number of rounds in a fair game would depend on the amount of money we start out with times the amount we need to get to the max. #Question 3 > ExactFairGR:=proc(i,N): local x,c,X,d: X:=RandomVariable(Bernoulli(.5)): x:=i: > c:=0: while x>0 and x x:=x-1 else x:=x+1 fi: od: if x=0 or x=N then RETURN([i/N,c]) end if: end proc > ExactFairGR(3,20) [3 ] [--, 13] [20 ] > EstGRt(.5,3,20,3000) [0.1530000000, 50] > #ExactFairGr and EstGRt both get near the same probability of winning, but > different round counts which is expected as they won't be exact because it's > entirely random. > #Question 4 P1:=RandSM(10) > StSa(P1,4000) [0.08300000000, 0.09375000000, 0.1160000000, 0.1147500000, 0.1110000000, 0.07725000000, 0.06500000000, 0.1232500000, 0.09350000000, 0.1225000000] > StSp(P1,4000) [Length of output exceeds limit of 1000000] > StS(P1) [ 86692435391167432765816620668897204 10403854286778317323622960971204896 [-------------------------------------, ------------------------------------, [1037458153341604777349093364080173827 115273128149067197483232596008908203 161600877685324870568481382773346225 125061666630210380546261140765753724 -------------------------------------, -------------------------------------, 1383277537788806369798791152106898436 1037458153341604777349093364080173827 222508736138144454766337806705096105 28125257452297366051372331487988040 -------------------------------------, ------------------------------------, 2074916306683209554698186728160347654 345819384447201592449697788026724609 8045188067978934733152455912343963 163619095998081740480735639929000409 ------------------------------------, -------------------------------------, 115273128149067197483232596008908203 1383277537788806369798791152106898436 11001186462689267543819838543754425 40368957091563001269153212985507065 ] ------------------------------------, ------------------------------------] 115273128149067197483232596008908203 345819384447201592449697788026724609] > P2:=RandSM(10) > StSa(P2,4000); StSp(P2,4000); StS(P2); P3:=RandSM(10); StSa(P3,4000); > StSp(P3,4000); StS(P3); P4:=RandSM(10); StSa(P4,4000); StSp(P4,4000); StS(P4); > P5:=RandSM(10); StSa(P5,4000); StSp(P5,4000); StS(P5); P6:=RandSM(10); > StSa(P6,4000); StSp(P6,4000); StS(P6); P7:=RandSM(10); StSa(P7,4000); > StSp(P7,4000); StS(P7); P8:=RandSM(10); StSa(P8,4000); StSp(P8,4000); StS(P8); > P9:=RandSM(10); StSa(P9,4000); StSp(P9,4000); StS(P9); P10:=RandSM(10); > StSa(P10,4000); StSp(P10,4000); StS(P10); [0.1077500000, 0.1295000000, 0.08325000000, 0.09150000000, 0.1132500000, 0.1015000000, 0.08325000000, 0.1062500000, 0.09175000000, 0.09200000000] [Length of output exceeds limit of 1000000] [129546109022334992377900748542396404 341035038358229483059377669323678037 [-------------------------------------, -------------------------------------, [1224489561799561759847423596949778809 2448979123599123519694847193899557618 2329991583987253150167327011541863 528869073856585012300408290194986306 -----------------------------------, -------------------------------------, 28476501437199110694126130161622763 6122447808997808799237117984748894045 650352786423512617510591457904482952 575081688274549471421778964146788792 -------------------------------------, -------------------------------------, 6122447808997808799237117984748894045 6122447808997808799237117984748894045 549413402556117925271342598347803352 283939087706710946738508520720027495 -------------------------------------, -------------------------------------, 6122447808997808799237117984748894045 2448979123599123519694847193899557618 1064297068849714285553537736934629627 1150936545261802332572066560769542869 --------------------------------------, -------------------------------------- 12244895617995617598474235969497788090 12244895617995617598474235969497788090 ] ] ] [0.09575000000, 0.1247500000, 0.09400000000, 0.09275000000, 0.1072500000, 0.1070000000, 0.1397500000, 0.07325000000, 0.06375000000, 0.1017500000] [Length of output exceeds limit of 1000000] [25242625405958187050992437095222447 148283579276544148683093191147385320 [------------------------------------, -------------------------------------, [275626873399248566886117706213941758 1240320930296618550987529677962737911 81379494039543293376299642431940315 13027319712913616755097219755710948 ------------------------------------, ------------------------------------, 826880620197745700658353118641825274 137813436699624283443058853106970879 79712433947112013709745639223269083 127653726269137980298773435602765233 ------------------------------------, -------------------------------------, 826880620197745700658353118641825274 1240320930296618550987529677962737911 60722404891692250548373573305065620 22952573483282547520380287475491037 ------------------------------------, ------------------------------------, 413440310098872850329176559320912637 275626873399248566886117706213941758 82065694962639473224083457201064584 124388550715431380140338713243902607 ] -------------------------------------, -------------------------------------] 1240320930296618550987529677962737911 1240320930296618550987529677962737911] [0.06000000000, 0.09550000000, 0.09300000000, 0.1232500000, 0.08575000000, 0.1120000000, 0.1090000000, 0.09375000000, 0.1170000000, 0.1107500000] [Length of output exceeds limit of 1000000] [ 81198294872682345413768797659842666 43072466011174413084735974736785480 [-------------------------------------, ------------------------------------, [1329303616110304664563596244107025347 443101205370101554854532081369008449 38952110653724812043691258676465174 167883735364778692374779304650125010 ------------------------------------, -------------------------------------, 443101205370101554854532081369008449 1329303616110304664563596244107025347 112311858534392888410375061575555948 142061491997364279329649496551626242 -------------------------------------, -------------------------------------, 1329303616110304664563596244107025347 1329303616110304664563596244107025347 47318570090867126446235803163038824 121453796511308334733647826297038008 ------------------------------------, -------------------------------------, 443101205370101554854532081369008449 1329303616110304664563596244107025347 55902813645046612926008104717246693 148656557627339230799362333492228960 ] ------------------------------------, -------------------------------------] 443101205370101554854532081369008449 1329303616110304664563596244107025347] [0.1015000000, 0.05575000000, 0.1142500000, 0.09425000000, 0.1020000000, 0.08225000000, 0.1205000000, 0.09850000000, 0.1225000000, 0.1085000000] [Length of output exceeds limit of 1000000] [91927568725814178316700872707719105 58376898201335047057690870240400175 [------------------------------------, ------------------------------------, [919160883258915957051380581196390221 919160883258915957051380581196390221 97674923729638096421062962345330870 174422024480181719250666218860623731 ------------------------------------, -------------------------------------, 919160883258915957051380581196390221 1838321766517831914102761162392780442 206561906513472610763935984047517247 291901225552024741114995786571924595 -------------------------------------, -------------------------------------, 1838321766517831914102761162392780442 3676643533035663828205522324785560884 412167168267007974801118054113483735 91970042617840865908318664415857536 -------------------------------------, ------------------------------------, 3676643533035663828205522324785560884 919160883258915957051380581196390221 122370592222694668856594693679413775 180663587620015513009365912364492377 ] ------------------------------------, -------------------------------------] 919160883258915957051380581196390221 1838321766517831914102761162392780442] [0.07975000000, 0.06650000000, 0.08475000000, 0.1227500000, 0.1295000000, 0.08350000000, 0.09000000000, 0.08625000000, 0.1400000000, 0.1170000000] [Length of output exceeds limit of 1000000] [47572503001087405265583416333127630 257092131118315929518374900083588480 [------------------------------------, -------------------------------------, [573448513450557291728300183812459771 4014139594153901042098101286687218397 338049683121974911922679335435619896 494234283373919242955310986304327000 -------------------------------------, -------------------------------------, 4014139594153901042098101286687218397 4014139594153901042098101286687218397 482840773363807835417369445646575644 339480931226909378796974872347163470 -------------------------------------, -------------------------------------, 4014139594153901042098101286687218397 4014139594153901042098101286687218397 54918508729118294777873554760295135 338054689743189024375085295838775200 ------------------------------------, -------------------------------------, 573448513450557291728300183812459771 4014139594153901042098101286687218397 80755080395550890050580828425286868 481664457325488588454041854400201276 ] ------------------------------------, -------------------------------------] 573448513450557291728300183812459771 4014139594153901042098101286687218397] [0.1270000000, 0.07025000000, 0.07825000000, 0.1040000000, 0.1322500000, 0.1147500000, 0.09450000000, 0.08950000000, 0.1055000000, 0.08400000000] [154479538350531290249634991317078238 90640329888947939192864043342750736 [-------------------------------------, -------------------------------------, [1245479822313953331528975019735070941 1245479822313953331528975019735070941 99062154098616056165429050148870745 130704983135825344163743503487910100 -------------------------------------, -------------------------------------, 1245479822313953331528975019735070941 1245479822313953331528975019735070941 169310581180788824875206566489290800 141131338292086953056666253272923162 -------------------------------------, -------------------------------------, 1245479822313953331528975019735070941 1245479822313953331528975019735070941 119523529859053292916152224108943055 105241601810066820199585871599414848 -------------------------------------, -------------------------------------, 1245479822313953331528975019735070941 1245479822313953331528975019735070941 132087039917248437677740418243677725 103298725780788373031952097724211532 ] -------------------------------------, -------------------------------------] 1245479822313953331528975019735070941 1245479822313953331528975019735070941] [0.08825000000, 0.08275000000, 0.09425000000, 0.09450000000, 0.08150000000, 0.09725000000, 0.1242500000, 0.1207500000, 0.1250000000, 0.09150000000] [Length of output exceeds limit of 1000000] [533580980735274096640093475668590041 158943297882732386173442172011459120 [-------------------------------------, -------------------------------------, [5607759440990965670095675941767809851 1869253146996988556698558647255936617 174215986530847816146638837517869945 174265625221396678025364539053419696 -------------------------------------, -------------------------------------, 1869253146996988556698558647255936617 1869253146996988556698558647255936617 909279513216569016130492007177465875 --------------------------------------, 11215518881981931340191351883535619702 377278878346100691744443454055978395 688648945495959288932628600864088988 -------------------------------------, -------------------------------------, 3738506293993977113397117294511873234 5607759440990965670095675941767809851 634430048212661125075038403080689533 226985186705929641507678768003536308 -------------------------------------, -------------------------------------, 5607759440990965670095675941767809851 1869253146996988556698558647255936617 527311103396916048206631327722885552 ] -------------------------------------] 5607759440990965670095675941767809851] [0.09525000000, 0.1015000000, 0.07550000000, 0.1110000000, 0.09700000000, 0.1062500000, 0.06850000000, 0.08575000000, 0.1192500000, 0.1400000000] [Length of output exceeds limit of 1000000] [186241333217030895634778594456424956 18467141711967480413531110506770831 [-------------------------------------, ------------------------------------, [2109324117676702288244806932389904081 162255701359746329864985148645377237 56251496831126068525925300256307612 81709822592217395177864353083022782 ------------------------------------, ------------------------------------, 703108039225567429414935644129968027 703108039225567429414935644129968027 69889377310103205427660778562991674 71522667281556530902105766524455770 ------------------------------------, ------------------------------------, 703108039225567429414935644129968027 703108039225567429414935644129968027 144349051532957733193068404327412053 195110199852863197071055694199951184 -------------------------------------, -------------------------------------, 2109324117676702288244806932389904081 2109324117676702288244806932389904081 73134277772794891857379406380667364 286027765454878941297192988395759479 ] ------------------------------------, -------------------------------------] 703108039225567429414935644129968027 2109324117676702288244806932389904081] [0.1137500000, 0.08550000000, 0.1040000000, 0.08150000000, 0.08750000000, 0.08300000000, 0.1050000000, 0.1147500000, 0.1180000000, 0.1070000000] [1856142024548616392105922168745278515 753590378312214385193486522183505770 [--------------------------------------, -------------------------------------, [17756823245868424953095319383780352246 8878411622934212476547659691890176123 319037625059850572603827416398388314 -------------------------------------, 2959470540978070825515886563963392041 1412622452166529733724620683849734565 --------------------------------------, 17756823245868424953095319383780352246 821554967521976971542921266212774766 255863281351311587634292467001728102 -------------------------------------, -------------------------------------, 8878411622934212476547659691890176123 2959470540978070825515886563963392041 905318943975746436363233728124632373 5156073137129856259353177986380915 -------------------------------------, -----------------------------------, 8878411622934212476547659691890176123 46483830486566557468835914617226053 1026555211831598765693243664214002925 342499064836604609529562146419549912 ] -------------------------------------, -------------------------------------] 8878411622934212476547659691890176123 2959470540978070825515886563963392041] >