#M14.txt: Maple code for Lecture 14 of Dynamical Modesl in Biology, Fall 2021 (taught by Dr. Z.) Help14:=proc(): print(` RevOp(n,k), RevOpTr(n,k) `):end: #RevOp(n,k): The operation of taking a k-digit number, sorting its digits from large to small, and subtractiong it from the revers. For example #RevOp(39,2) should give 93-39=54 RevOp:=proc(n,k) local L,L1,L2,i: if not (type(n,integer) and n>=0 and n<10^k) then print(`Bad input`): RETURN(FAIL): fi: L:=convert(n,base, 10): L1:=sort([op(L),0$(k-nops(L))]): L2:=[seq(L1[k+1-i],i=1..k)]: add(L1[i]*10^(i-1),i=1..k)-add(L2[i]*10^(i-1),i=1..k): end: #RevOpTr(n,k): The trajectory of the dynamical system RevOp(n,k) until it hits the first repetition (and then it keeps cycling for ever) RevOpTr:=proc(n,k) local L,n1: if not (type(n,integer) and n>=0 and n<10^k) then RETURN(FAIL): fi: L:=[]: n1:=n: while not member(n1,L) do L:=[op(L),n1]: n1:=RevOp(n1,k): od: [op(L),n1]: end: