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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education