#Ross Berkowitz hw26.txt #Posting Permission Granted Help:=proc(): print("ExpD2(M,N)"): end: ExpD2:=proc(N,M) local a,eq,var,i,j: var:={seq( seq(a[i][j],j=0..M), i=0..N)}: eq:={seq(a[i][0],i=0..N),seq(a[0][j],j=0..M), seq(a[i][M],i=0..N),seq(a[N][j],j=0..M), seq(seq(a[i][j]=1+1/4*( a[i-1][j]+ a[i][j-1]+ a[i+1][j]+ a[i][j+1] ),j=1..M-1) ,i=1..N-1) }: var:=solve(eq,var): if var=NULL then RETURN(FAIL): fi: subs(var,[seq( [seq(a[i][j],j=0..M)], i=0..N)]): end: ################### OLD STUFF ################### #C26.txt, Gambler's ruin, April 28, 2014 Help26:=proc(): print(`Die1(p), GR(i,N,p), ExpD(N,p)`): print(`ExpDf(N,p) , PGF(N,p,t), PGFf(N,p,t), GuessP(L,x) `): end: #Die1: inputs p rational between 0 and 1 #and outputs 1 with prob. p and 0 with prob. 1-p Die1:=proc(p) local a,b,ra: a:=numer(p): b:=denom(p): ra:=rand(1..b)(): if ra<=a then 1: else -1: fi: end: #GR(i,N,p): simulates a gambler's ruin session #staring with i dollars, ending with 0 or N dollars #and with prob. of winning a dollar =p GR:=proc(i,N,p) local x,j: x:=i: for j from 0 while (x>0 and xFAIL then RETURN(gu): fi: od: FAIL: end: #end Added after class