#Nathan Fox #Homework 27 #I give permission for this work to be posted online #Read procedures from class read(`C27.txt`): Help:=proc(): print(` ProbW(N,p) `): end: ##PROBLEM 2## #ProbW(N,p): inputs a positive integer N, a number p between 0 #and 1, and outputs a list of length N-1 whose i-th entry tells #you the probability of exiting the casino a winner, if you start #out with i dollars, and must leave as soon as you are either #broke or have N dollars. ProbW:=proc(N, p) local eq, var, var1, f, i: var:=[seq(f[i], i=1..N-1)]: eq:={seq(f[i]=p*f[i+1] + (1-p)*f[i-1], i=1..N-1)}: eq:=subs({f[0]=0, f[N]=1}, eq): var1:=solve(eq, convert(var, set)): return subs(var1, var): end: #ProbW(50, 1/2); returns [1/50, 1/25, 3/50, 2/25, 1/10, 3/25, 7/50, 4/25, 9/50, 1/5, 11/50, 6/25, 13/50, 7/25, 3/10, 8/25, 17/50, 9/25, 19/50, 2/5, 21/50, 11/25, 23/50, 12/25, 1/2, 13/25, 27/50, 14/25, 29/50, 3/5, 31/50, 16/25, 33/50, 17/25, 7/10, 18/25, 37/50, 19/25, 39/50, 4/5, 41/50, 21/25, 43/50, 22/25, 9/10, 23/25, 47/50, 24/25, 49/50] #evalf(ProbW(50, 17/35)); returns [.3581285228e-2, .7373234292e-2, .1138823918e-1, .1563942083e-1, .2014067199e-1, .2490670263e-1, .2995308801e-1, .3529631959e-1, .4095385892e-1, .4694419467e-1, .5328690311e-1, .6000271205e-1, .6711356858e-1, .7464271078e-1, .8261474370e-1, .9105571973e-1, .9999322377e-1, .1094564633, .1194763641, .1300856707, .1413190542, .1532132250, .1658070528, .1791416941, .1932607261, .2082102893, .2240392386, .2407993026, .2585452526, .2773350821, .2972301957, .3182956101, .3406001665, .3642167557, .3892225559, .4156992856, .4437334700, .4734167241, .5048460519, .5381241637, .5733598115, .6106681445, .6501710852, .6919977284, .7362847624, .7831769160, .8328274316, .8853985657, .9410621195] #evalf(ProbW(50, 49/100)); returns [.6386504851e-2, .1303368337e-1, .1995217530e-1, .2715305465e-1, .3464784744e-1, .4244855015e-1, .5056764888e-1, .5901813940e-1, .6781354790e-1, .7696795267e-1, .8649600660e-1, .9641296070e-1, .1067346884, .1174777112, .1286592247, .1402971264, .1524100446, .1650173676, .1781392752, .1917967709, .2060117154, .2208068617, .2362058915, .2522334531, .2689152010, .2862778365, .3043491510, .3231580701, .3427347003, .3631103766, .3843177131, .4063906553, .4293645338, .4532761217, .4781636927, .5040670830, .5310277545, .5590888615, .5882953199, .6186938787, .6503331949, .6832639118, .7175387395, .7532125399, .7903424137, .8289877926, .8692105339, .9110750197, .9546482600]