COLLATZ
The Collatz Sequence


COLLATZ is a library of MATLAB routines for computing the Collatz sequence.

The rules for generation of the Collatz sequence are recursive. If T is the current entry of the sequence, (T is assumed to be a positive integer), then the next entry, U is determined as follows:

  1. if T is 1, terminate the sequence;
  2. else if T is even, U = T/2.
  3. else (if T is odd and not 1), U = 3*T+1;

Although the Collatz sequence seems to be finite for every starting point, this has not been proved. Over the range of starting values that have been examined, a great irregularity has been observed in the number of entries in the corresponding sequence.

The Collatz sequence is also known as the "hailstone" sequence or the "3n+1" sequence.

Related Data and Programs:

COLLATZ is also available in a MATHEMATICA version.

SEQUENCE_STREAK is a MATLAB program that can be used to make a "streak plot" of a Collatz sequence for a particular starting value, or for the length of the Collatz sequence for a number of starting values.

The TABLE format is used for the file output by COLLATZ_WRITE.

Reference:

  1. Eric Weisstein,
    "The Collatz Problem",
    CRC Concise Encyclopedia of Mathematics,
    CRC 1998.

Source Code:

Examples and Tests:

collatz_27 lists the Collatz sequence for seed 27.

collatz_count lists the number of entries in each Collatz sequence with seeds from 1 to 100.

You can go up one level to the MATLAB source codes.


Last revised on 25 February 2006.