#Nathan Fox #Homework 8 #I give permission for this work to be posted online #Read packages with(`combinat`): #Read procedures from class read(`C9.txt`): #Help procedure Help:=proc(): print(` ExpectedDurationE(N, p) , GRsimWL(N, a, p, K) `): end: ##PROBLEM 1## #Conjecture: f(N, a) = a/N #This checks out with the system, and the boundary conditions work, #so it's right ##PROBLEM 2## #ExpectedDurationE(N, p): inputs N (the exit capital if you are a #winner), and p (the probability of winning a dollar at each #round), and outputs the list of length N-1 whose a-th entry is #the expected duration of the game (exiting either a winner #or loser). ExpectedDurationE:=proc(N, p) local E, eq, var, i, sol: var:={seq(E[i],i=0..N)}: eq:={E[0]=0, E[N]=0, seq(E[i]=1+p*E[i+1]+(1-p)*E[i-1], i=1..N-1)}: sol:=solve(eq, var): return subs(sol, [seq(E[i],i=1..N-1)]): end: ##PROBLEM 3## #Conjecture: g(a, N)=a*(N-a) #This checks out with the system, and the boundary conditions work, #so it's right ##PROBLEM 4## #It checks out ##PROBLEM 5## #For N=50, PrE(N,9/19)[N/2] is 0.06698122976 #For N=80, PrE(N,9/19)[N/2] is 0.01456559065 #For N=100, PrE(N,9/19)[N/2] is 0.005127349998 #These are probabilities of winning, and they are all really small, #so gambling is bad ##PROBLEM 6## #GRsimWL(N, a, p, K): the gambler goes to the casino K #times and does GR(N, a, p) #Returns a triple of numbers. The first number is as before, the #ratio of wins to K, the second number is the average duration of #the games where he exited a winner, and the third number is the #average duration of the games where he exited a loser. GRsimWL:=proc(N, a, p, K) local w, d, i, g: w:=0: d:=[0$2]: for i from 1 to K do g:=GR(N, a, p): w:=w+g[1]: d[g[1]+1]:=d[g[1]+1]+g[2]: od: return evalf(w/K), evalf(d[2]/w), evalf(d[1]/(K-w)): end: