Heights of Collatz Trajectories

Math 242 Modern Computational Mathematics

Preliminary Code

Here is our basic code for defining the Collatz function and computing trajectories.

col[n_?OddQ]:=3n+1
col[n_?EvenQ]:=n/2
computeTrajectory[start_,maxIter_:100000]:=Module[{traj={start},n=start},
(* compute the trajectory until we find 1 *)
While[n!=1&&Length[traj]<maxIter,
n=col[n];
AppendTo[traj,n];
];
(* return the trajectory *)
traj
]

Stopping time of Collatz trajectories

Recall from the text that stop(n) is the number of iterations of the function col required to reach 1 from n.