Exploring a Variant of the Collatz Function

Math 242 Modern Computational Mathematics

Define a new function

Let’s modify the Collatz function by changing 3n+1 to 3n-1. That is, define ColVar(n)=3n-1 if n is odd, and ColVar(n)=(n/2) if n is even.

colVar[n_?OddQ]:=3n-1
colVar[n_?EvenQ]:=n/2

Here is a modified version of our makeSeq module from a week ago. This version takes three inputs: a function, a starting value, and a number of iterations; it returns a sequence of iterates.

makeSeq[func_,start_,numIter_]:=Module[{n=start,seq={start}},
Do[
(* compute the next value and append to the sequence *)
n=func[n];
AppendTo[seq,n],

{numIter} (* repeat numIter times *)
];

(* return the sequence *)
seq
]