#DMB6.txt: Maple Code for Dr. Z.'s Dynamical Models in Biology class, Lecture 6, Sept. 19, 2025 with(linalg): print(`For a list of the Main procedures type: Help6(); for help with a specific procedure type: Help6(ProcedureName); for example Help6(RandomMC);`): print(`For a list of the other procedures type: Help6a(); for help with a specific procedure type: Help6(ProcedureName); for example Help6(RandomMC);`): Help6a:=proc() if nargs=0 then print(`The other procedures are: raFV, raSV `): else Help6(args): fi: end: Help6:=proc() if nargs=0 then print(`The available procedures are: Leslie, RandomLeslieMatrix, RandomMC `): elif nargs=1 and args[1]=Leslie then print(`Leslie(FV,SV): Given a fetrilty vector FV and a survival vector SV (whose size is one less than that of FV, outputs the`): print(`corresponding Leslie matrix. Try:`): print(`Leslie[[0,0.5,1.4,2.1],[0.5,0.7,0.5]);`): elif nargs=1 and args[1]=PageRank then print(`PageRank(A,n): Given a stochastic matrix A representing an internet, outputs the page rank`): print(`Try: A:=RamdomMC(6): PageRank(A,6):`): elif nargs=1 and args[1]=raFV then print(`raFV(A): a random fertility vector [f_0, ..., f_A] where f_0=0 and f_i are less than K `): print(`Try:`): print(`raFV(5,3);`): elif nargs=1 and args[1]=raSV then print(`raSV(A): a random survival vector [p_0, ..., p_(A-1]] where the components are beteen 0 and 1 `): print(`Try:`): print(`raSV(5);`): elif nargs=1 and args[1]=RandomLeslieMatrix then print(`RandomLeslieMatrix(A,K): inputs the maximal age for fertile females, and a positive integer K outputs an (A+1) by (A+1) Leslie matrix with`): print(`fertilty rates up to K1 and random survial rates. Try`): print(`RandomLeslieMatrix(5,3);`): elif nargs=1 and args[1]=RandomMC then print(`RandomMC(n): A random Markov chain . Try:`): print(`RandomMC(5);`): else print(`There is no Help for`, args): fi: end: #raSV(A): a random survial vector [p_0, ..., p_(A-1]] where the components are beteen 0 and 1 and p_0=0, but the other survival rates are larger than 0 and strictly less than 1 #Try: #raSV(5); raSV:=proc(A) local ra,i: ra:=rand(1..99): evalf([seq(ra()/100,i=1..A)]); end: #raFV(A,K): a random Fertiligy vector [f_0, ..., f_(A]] where the components are less than K, f_0=0 #Try: #raFV(5,K); raFV:=proc(A,K) local ra,i: ra:=rand(1..99*K): evalf([0,seq(ra()/100,i=1..A)]); end: #Leslie(FV,SV): Given a fetrilty vector FV and a survival vector SV (whose size is one less than that of FV, outputs the #corresponding Leslie matrix Leslie:=proc(FV,SV) local A,i: A:=nops(SV): if nops(FV)<>A+1 then RETURN(FAIL): fi: matrix([FV,seq([0$i,SV[i+1],0$(A-i)],i=0..A-1)]): end: #RandomLeslieMatrix(A,K): inputs the maximal age for fertile females, and a positive integer K outputs an (A+1) by (A+1) Leslie matrix with #fertilty rates up to K1 and random survial rates. Try #RandomLeslieMatrix(5,3); RandomLeslieMatrix:=proc(A,K) local FV, SV: FV:=raFV(A,K): SV:=raSV(A): Leslie(FV,SV): end: #RandomMC(n): A random Markov chain . Try: #RandomMC(5); RandomMC:=proc(n) local i,L,L1,i1,ra,s: ra:=rand(1..10): L:=[]: for i from 1 to n do L1:=[seq(ra(),i1=1..n)]: s:=convert(L1,`+`): L1:=[seq(L1[i1]/s,i1=1..n)]: L:=[op(L),L1]: od: matrix(L): end: #PageRank(A,n): Given a stochastic matrix A representing an internet, outputs the page rank #Try: A:=RamdomMC(6): PageRank(A,6): PageRank:=proc(A,n) local B,i: B:=evalm(A^1000): [seq(B[1,i],i=1..n)]: end: