#Kafung Mok #HW 17 #March 30, 2014 ############################################## Class Notes March 27 ################################################## #C17.txt: March 27, 2014 #Discrete Calculus Help:=proc(): print(` GPi(N) , Dsin(x,h) , Srec(L,Ini,n)`): print(` dBVP(L,Ini,Fini,N) `): end: #GPi(N): the geometrical discrete Pi #the number of lattice points (x,y) such #that x^2+y^2nops(Ini) then print(Ini, L, `should be lists of the SAME length `): RETURN(FAIL): fi: if n<0 then 0: elif nnops(Ini)+nops(Fini) then RETURN(FAIL): fi: var:={seq(a[i],i=0..N)}: eq:={seq(a[i]=Ini[i+1],i=0..nops(Ini)-1), seq(a[N-i]=Fini[i+1],i=0..nops(Fini)-1)}: eq:= eq union {seq(a[i]-add(L[j]*a[i-j],j=1..nops(L)), i=nops(L)..N)}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): else subs(var,[seq(a[i],i=0..N)]): fi: end: ########################################### End of Class Notes March 27 ############################################### ############# # Problem 1 # ############# #SIrec(L,Ini,f,n,N): has the same input as Srec but in addition #an expression, f, in the discerte variable n, that solves #Inhomogeneous linear recurrences #a(n)=L[1]*a(n-1)+L[2]*a(n-2)+ ... + L[-1]*a(n-nops(L))+f(n) SIrec:=proc(L,Ini,f,n,N) local i: option remember: if nops(L)<>nops(Ini) then print(Ini, L, `should be lists of the SAME length `): RETURN(FAIL): fi: if n<0 then 0: elif nnops(Ini)+nops(Fini) then RETURN(FAIL): fi: var:={seq(a[i],i=0..N)}: eq:={seq(a[i]=Ini[i+1],i=0..nops(Ini)-1), seq(a[N-i]=Fini[i+1],i=0..nops(Fini)-1)}: eq:= eq union {seq(a[i]-add(L[j]*a[i-j],j=1..nops(L))-subs(n=N,f), i=nops(L)..N)}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): else subs(var,[seq(a[i],i=0..N)]): fi: end: ############# # Problem 3 # ############# #GR(p,N):inputs a real number p, between 0 and 1 (or symbolic), and a positive integer N, and outputting #a list of length N+1, let's call it G, such G[i+1] is your chance of exiting a winner in a casino with #the following rule: if you enter a casino with i dollars where at each step you win a dollar with #probability p and lose a dollar with probability 1-p, and you stop playing when you are either #broke (0 dollars), or got N dollars. #Note:G[1]=0 and G[N+1]=1 GR:=proc(p,N) G:=dBVP([1/p,-(1-p)/p],[0],[1],N) : end: