COLLATZ
The Collatz Sequence
COLLATZ
is a MATLAB library which
computes 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:
-
if T is 1, terminate the sequence;
-
else if T is even, U = T/2.
-
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.
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
COLLATZ is available in
a JAVA version and
a MATHEMATICA version and
a MATLAB version and
a PERL version.
Related Data and Programs:
COLLATZ_PARFOR,
a MATLAB program which
seeks the maximum Collatz sequence between 1 and N; it runs in parallel
using MATLAB's "parfor" facility.
COLLATZ_RECURSIVE,
a MATLAB library which
demonstrates recursive programming by considering the simple Collatz 3n+1 problem.
POLPAK,
a MATLAB library which
includes the routine collatz_count for counting the
length of a Collatz sequence.
SEQUENCE_STREAK_DISPLAY,
a MATLAB program which
can display a "streak plot" of a van der Corput sequence.
TABLE,
a data format which
is used for the file output by COLLATZ_WRITE.
Reference:
-
Eric Weisstein,
"The Collatz Problem",
CRC Concise Encyclopedia of Mathematics,
CRC Press, 2002,
Second edition,
ISBN: 1584883472,
LC: QA5.W45.
Source Code:
-
collatz.m,
computes the Collatz sequence for a given starting point;
-
collatz_count.m,
returns the number of entries in the Collatz sequence
for a given starting point;
-
collatz_max.m,
returns the maximum entry in the Collatz sequence
for a given starting point;
-
collatz_write.m,
writes a Collatz sequence to a file;
-
timestamp.m,
prints the current YMDHMS date as a timestamp;
Examples and Tests:
-
collatz_test.m,
runs all the tests.
-
collatz_test_output.txt,
the output from the tests.
-
collatz_test01.m,
computes the Collatz sequence for several seeds.
-
collatz_test02.m,
computes the length of the Collatz sequence for seeds 1 to 100.
-
collatz_test03.m,
writes the Collatz sequence for seed 27 to a file, and the
Collatz sequence lengths for seeds 1 to 100 to a file.
-
collatz_27.txt,
the points in the Collatz sequence for seed 27.
-
collatz_count.txt,
the Collatz count for seeds 1 to 100.
-
collatz_test04.m,
displays the Collatz sequence for seed 27.
-
collatz_sequence_27.png,
a plot of the Collatz sequence for seed 27.
-
collatz_test05.m,
displays the Collatz max for seeds 1 to 1000.
-
collatz_max.png,
a plot of the Collatz max values for seeds 1 to 1000.
-
collatz_test06.m,
displays the Collatz count for seeds 1 to 50.
-
collatz_count.png,
a plot of the Collatz coount values for seeds 1 to 50.
You can go up one level to
the MATLAB source codes.
Last revised on 22 May 2012.