Consider the following algorithm: Start with a positive integer. If the number is even,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following algorithm: ■ Start with a positive integer. ■ If the number is even, divide it by two; otherwise triple it and add one. ▪ Repeat the process until the number 1 is obtained. The Collatz conjecture states that the above algorithm will reach 1 eventually for any starting value. Remarkably, for a problem that can be described so simply, it is an unsolved problem in mathematics as to whether the conjecture is true and its proof has been described as "completely out of reach of present day mathematics". Complete the below function collatz that applies the above algorithm for a given postive integer n and returns the number of steps required to reach a value of 1. If the number of steps reaches the value of max_steps (without the algorithm reaching 1) then NaN is returned. Your code must use a for loop and at least one if statement. Examples: (i) The following code steps = collatz (6,100) should return: steps = 8 since it takes 8 steps starting with a value of 6 to reach 1 (values generated along the way are: 3, 10, 5, 16, 8, 4, 2, 1). (ii) The following code steps = collatz (6,4) should return: steps = NaN since after 4 steps the algorithm has not reached 1 when starting with a value of 6. Consider the following algorithm: ■ Start with a positive integer. ■ If the number is even, divide it by two; otherwise triple it and add one. ▪ Repeat the process until the number 1 is obtained. The Collatz conjecture states that the above algorithm will reach 1 eventually for any starting value. Remarkably, for a problem that can be described so simply, it is an unsolved problem in mathematics as to whether the conjecture is true and its proof has been described as "completely out of reach of present day mathematics". Complete the below function collatz that applies the above algorithm for a given postive integer n and returns the number of steps required to reach a value of 1. If the number of steps reaches the value of max_steps (without the algorithm reaching 1) then NaN is returned. Your code must use a for loop and at least one if statement. Examples: (i) The following code steps = collatz (6,100) should return: steps = 8 since it takes 8 steps starting with a value of 6 to reach 1 (values generated along the way are: 3, 10, 5, 16, 8, 4, 2, 1). (ii) The following code steps = collatz (6,4) should return: steps = NaN since after 4 steps the algorithm has not reached 1 when starting with a value of 6.
Expert Answer:
Answer rating: 100% (QA)
Step 12 Answer Lets solve this question in the MATLAB programming language The logic of the program ... View the full answer
Related Book For
An Introduction to Statistical Methods and Data Analysis
ISBN: 978-1305269477
7th edition
Authors: R. Lyman Ott, Micheal T. Longnecker
Posted Date:
Students also viewed these electrical engineering questions
-
It is common in many countries that governments subsidize the production of goods in certain large oligopolistic industries. Common examples include aircraft industries and car industries. A: Suppose...
-
Rent controls force landlords to price apartments below the equilibrium price level. An immediate effect is a shortage (excess demand) of apartments, because the quantity of apartments demanded is...
-
If a price ceiling were imposed in a fish market whose equilibrium price was substantially above the ceiling, what effect would the price ceiling on fish have on the demand for meat and fowl?
-
Give the decoding key for the encoding keys in Problems 2536. Minus 4, divide by 2.
-
If you have traveled to poor developing countries, you will have noticed that people there consume very different goods and services than U.S. consumers. Does this mean that tastes in developing...
-
The formation of tetrafluoroethylene from its elements is highly exothermic: (a) If a mixture of F2, graphite, and C2F4 is at equilibrium in a closed container, will the reaction go to the right or...
-
For the seven-member planar truss considered in Problem 12.6 (Fig. 12.18), determine the assembled stiffness matrix of the system before applying the boundary conditions. Data From Problem 12.6:- A...
-
For Simonsen Village, prepare a government-wide statement of net position and statement of activities, and a governmental funds balance sheet and statement of revenues, expenditures, and changes in...
-
How does the Internet facilitate piracy? How might we explain the high levels of involvement in such practices by young people? Whose interests does the criminalization of copying serve? Is there a...
-
Vitex, Inc. manufactures a popular consumer product and it has provided the following data excerpts from its standard cost system: The company's manufacturing overhead cost is applied to production...
-
On July 1, 2005, Knudsen purchased 13-year, 7% bonds having maturity a value of $448,000. Interest is paid semi-annually on June 30 and December 31 and the bonds provide the bondholders a 15% yield....
-
Damon Telecom is designing a new workhorse satellite to eventually replace all the orbital satellites it manages in its telecommunication network. The design of this satellite consists of five...
-
In some stem-and-leaf displays with one or two unusually low values, the first stem is often written as LOW, with the complete values in the leaf section. Why and when might we do this?
-
If a sampling plan used a sample size of n = 100 for batches of N = 1,000 units with a 58.3% chance of accepting batches that have an actual proportion defective of p = 10%, what AOQ would result...
-
Do shallow waves propagate at the same speed in all fluids? Explain why or why not.
-
In addition to comparing the reaction times as a function of rotation, how else might you use these data to draw conclusions about how people process information?
-
Write a function to check whether a given number is prime or not.
-
Use this circle graph to answer following Exercises. 1. What fraction of areas maintained by the National Park Service are designated as National Recreation Areas? 2. What fraction of areas...
-
The test for screening donated blood for the presence of the AIDS virus was developed in the 1980s. It is designed to detect antibodies, substances produced in the body of donors carrying the virus;...
-
The sample mean to be calculated from a random sample of size n = 4 from a population that consists of eight measurements (2, 6, 9, 12, 25, 29, 39, 50). Find the sampling distribution of y.
-
Refer to Exercise 14.5. When the normality condition is violated, an alternative to the F test is the Kruskal Wallis test (see Section 8.6). a. Test for differences in the median outputs of the four...
-
What is meant by a cap and floor?
-
What is the impact on interest rate risk of including a cap and/or floor in the coupon structure?
-
The pricing expression for a risky floater can be thought of as possessing two components. Explain.
Study smarter with the SolutionInn App