Question: For MATLAB Consider a sequence {0,1,2,}, where 0 is some natural number and +1= (an/2 if an is even and 3an + 1 if an
For MATLAB
Consider a sequence {0,1,2,}, where 0 is some natural number and +1= (an/2 if an is even and 3an + 1 if an is odd)
For example, if 0= 3, then we have {3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1} and if 0= 9, then {9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1}. In fact, as far as we know, the sequence eventually reaches 1 starting from any natural number (in other words, there is no known counterexample). On the other hand, the statement that it reaches 1 for all natural numbers, known as the Collatz conjecture, is one of the great unsolved problems in mathematics (see, for example, Collatz conjecture in Wikipedia). Write a function with header [period, a_max] = myCollatz(a0), where period is the length of the sequence before it reaches the first 1 and a_max is the maximum number in this sequence. For example:
[period, a_max] = myCollatz(9)
period = 19
a_max = 52
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
