Pick a number, any number (actually, make it a positive integer). Now, let's play a game. If your number is even, divide it by 2. If it is odd, multiply it by 3 and add 1. Repeat this process with your new number. Repeat over and over again. Lothar Collatz in 1937 guessed that this process will always eventually end at the number 1. Write a Matlab function file that takes an input n (assume the user enters a positive integer) and runs through the Collatz process until a 1 is reached. The function should output count, the number of iterations necessary to reach 1. As a test, your code should report that 63 iterations are necessary if we start with the number 2020.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 34SA
icon
Related questions
Question
100%
We will now use your working Collatz code to create a plot like this one on Wikipedia: CollatzPlot
Create an array of integers from 1 to 10,000 called x.
Then use the collatz function to create another array y of the Collatz stopping time for each entry of x. For
example, the 2019th entry in y should be 112.
Plotting y vs x will produce the plot shown on the link above.
NOTE: If your code is slow or does not finish, remember to use semicolons inside of loops!
Transcribed Image Text:We will now use your working Collatz code to create a plot like this one on Wikipedia: CollatzPlot Create an array of integers from 1 to 10,000 called x. Then use the collatz function to create another array y of the Collatz stopping time for each entry of x. For example, the 2019th entry in y should be 112. Plotting y vs x will produce the plot shown on the link above. NOTE: If your code is slow or does not finish, remember to use semicolons inside of loops!
Pick a number, any number (actually, make it a positive integer). Now, let's play a game. If your number is
even, divide it by 2. If it is odd, multiply it by 3 and add 1. Repeat this process with your new number.
Repeat over and over again. Lothar Collatz in 1937 guessed that this process will always eventually end at
the number 1. Write a Matlab function file that takes an input n (assume the user enters a positive integer)
and runs through the Collatz process until a 1 is reached. The function should output count, the number
of iterations necessary to reach 1. As a test, your code should report that 63 iterations are necessary if we
start with the number 2020.
Transcribed Image Text:Pick a number, any number (actually, make it a positive integer). Now, let's play a game. If your number is even, divide it by 2. If it is odd, multiply it by 3 and add 1. Repeat this process with your new number. Repeat over and over again. Lothar Collatz in 1937 guessed that this process will always eventually end at the number 1. Write a Matlab function file that takes an input n (assume the user enters a positive integer) and runs through the Collatz process until a 1 is reached. The function should output count, the number of iterations necessary to reach 1. As a test, your code should report that 63 iterations are necessary if we start with the number 2020.
Expert Solution
Step 1

Actually, program is a executable software that runs on a computer.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning