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.
-
How do the basic methods of distribution affect advertising?
-
Indole reacts with electrophile at C3 rather than at C2. Draw resonance forms of the intermediate cations resulting from reaction at C2 and C3, and explain the observed results.
-
Diageo North America, Inc., the owner of the Bulleit brand family of whiskeys, sued competitor W.J. Deutsch & Sons Ltd. for allegedly infringing upon the trade dress of Diageos Bulleit bottles....
-
The Walton Toy Company manufactures a line of dolls and a doll dress sewing kit. Demand for the dolls is increasing, and management requests assistance from you in determining an economical sales and...
-
Pioneer Inc. wants to invest $557,302 today. The expected returns in years 1, 2, and 3 are $247,615, $180,383, and $335,481, respectively. If the rate of return on investment must be at least 14%,...
-
A firm must decide between constructing a new facility or renting a comparable office space. There are two random outcomes for acquiring space, as shown in Figure PI 2-25. Each would accommodate the...
-
Question 5 Fourteen (12) variables were considered in a study to reflect different attitudes towards teacher's work environment. A preliminary analysis was conducted on the correlation values among...
-
david and dinah are married. the couple has 2children; dough whois 14 years old and desiree who is 22 years old.. Dough is in high school eve though he earns 7500 per year through summer part time...
-
What is a designated router and what is its role. What Designated routers usually exist on an OSPF network and how are they chosen?
-
Headings are for convenience only and do not affect interpretation' is an example of what type of boilerplate clause?
-
1.3a Explain loopless finite automata* 1. Describe a state-based model of computation that accepts exactly the finite languages. Describe a transition-system model of computation that has no loops,...
-
Adidas decides to invest $100,000,000 into a shoe factory in Vietnam from its money market account. The money market account was earning 1% in interest per year or $1,000,000. Adidas could have also...
-
1. In deriving government spending multiplier we assumed that government spending is exogenously fixed. However, it is also possible that government spending (G) increases with domestic income (Y)....
-
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...
-
Which of the following types of epigenetic changes may promote cancer? a. DNA methylation b. Covalent modification of histones c. Chromatin remodeling d. All of the above may promote cancer.
-
The underlying cause(s) of epigenetic changes associated with cancer may be a. mutations in genes that encode chromatin-modifying proteins. b. environmental agents that alter the function of...
-
Normal (nonmutant) tumor-suppressor genes often function a. as negative regulators of cell division. b. in the maintenance of genome integrity. c. in the stimulation of cell division. d. as both a...
Study smarter with the SolutionInn App