Write a function collatzseg (n) which computes the Collatz sequence (as a Python list) given an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function collatzseg (n) which computes the Collatz sequence (as a Python list) given an initial value n. For example, the output of collatzseq (5) should be [5,16,8,4,2,11 (ii) Write a function collatzcount (n) which counts the number of steps s(n) until the sequence starting at 12 reaches 1. For example, s(1) = 0 and as above s(11) = 14. (iii) Plot a graph of s(n) against n for n € [1, 1000]. Use circles for markers instead of lines. (iv) What percentage of initial values n have the property that s(n) <n/10 for n = [1, 1000]? (Write your answer as a comment, including any code you used to obtain it but commented out.) (v) Let max(n) be the largest integer reached by the sequence with initial value n before ending at 1. That is, max(n) = max(A, | Aon). For example, in the case above, max(11) = 52. Plot a graph of max(n) against n for n E [1, 1000]. Investigate using different plotting techniques such as: restricting the y-axis, logarithmic plots, using a bigger range for x (so long as this doesn't make your code too slow), or plotting additional points or lines to help identify any patterns you can see. Comment on your observations (including your answer as a comment). Write a function collatzseg (n) which computes the Collatz sequence (as a Python list) given an initial value n. For example, the output of collatzseq (5) should be [5,16,8,4,2,11 (ii) Write a function collatzcount (n) which counts the number of steps s(n) until the sequence starting at 12 reaches 1. For example, s(1) = 0 and as above s(11) = 14. (iii) Plot a graph of s(n) against n for n € [1, 1000]. Use circles for markers instead of lines. (iv) What percentage of initial values n have the property that s(n) <n/10 for n = [1, 1000]? (Write your answer as a comment, including any code you used to obtain it but commented out.) (v) Let max(n) be the largest integer reached by the sequence with initial value n before ending at 1. That is, max(n) = max(A, | Aon). For example, in the case above, max(11) = 52. Plot a graph of max(n) against n for n E [1, 1000]. Investigate using different plotting techniques such as: restricting the y-axis, logarithmic plots, using a bigger range for x (so long as this doesn't make your code too slow), or plotting additional points or lines to help identify any patterns you can see. Comment on your observations (including your answer as a comment).
Expert Answer:
Answer rating: 100% (QA)
Heres a Python script that includes the functions described in your question along with code for plo... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
On 1/1/22, lmani and Ahmad formed AI Partnership, a limited partnership. lmani will be the general partner and Ahmad will be a limited partner. He will not participate in management of the...
-
Find Io in the network shown. 12 mA
-
Express each of the given expressions in simplest form with only positive exponents. (7a 1 x) 3
-
Use the power state machine of Fig. 8.12 to determine the energy used in these use cases: a. idle 1 s; receive 10 ms; idle 0.1 s; transmit 5 s; b. sleep 1 min; receive 50 ms; idle 0.1 s; receive 100...
-
Bedard Corporation reported net income of $300,000 in 2010 and had 200,000 shares of common stock outstanding throughout the year. Also outstanding all year were 45,000 options to purchase common...
-
Amaya Keele: Assume that the facility emits certain pollutants into The air. RCPC wishes to partially reconstruct the facility after its purchase for purposes of being able to run the facility for...
-
1. Based on what you read in this chapter, what would you have suggested Lisa and her team do first with respect to training, particularly in terms of the companys strategy? Why? 2. Have Lisa and the...
-
XYZ Corporation is considering two mutually exclusive projects that require a $150,000 investment each. Project A has an expected life of 6 years and will generate net cash flows of $35,000 per year....
-
What will be displayed on the console given the following code fragment? int main() { int num1 = 3; int num2 = 4; myFunction (num1, num2); return 0; } void myFunction (int num1Par, int num2Par) {...
-
the finished products have been received in the Inventory, the Manufacturing Output Settlement Variance has been added. Explain how is this figure (101.323.35) calculated by the system?
-
What is the most memorable speech that you have ever heard? What about this speech made it so memorable?
-
Question 4 Maicon ple acquired 75 percent of the ordinary share capital of Rodwell Limited on 1 January 2011, when the balance on the retained earnings reserve of Rodwell Limited was 250,000. Maicon...
-
Use the following program for the questions below that ask about operand evaluation mechanisms. int global = 7; int funct] () { global --; return 3; } int funct2 (int & para) { Para -- return 3; }...
-
Black Berry Farms and Pea Pod Farms are each able to generate EBIT of $150,000. The separate capital structures for Black Berry and Pea Pod are presented below. Black Berry a Pod Debt e 10% $800,000...
-
What is the back work ratio? What are typical back work ratio values for gas-turbine engines?
-
The problem in our initial discussion of A-grade insurance markets was that adverse selection led to non-randomness in the insurance pool: Although almost everyone was willing to pay the insurance...
-
Financing a Strategic Investment under Quantity Competition: Suppose you own a firm that has invented a patented product that grants you monopoly power. Patents only last for a fixed period of time ...
-
As we have suggested in the chapter, it is often important to know whether workers will work more or less as their wage increases. A. In each of the following cases, can you tell whether a worker...
-
The relativity of simultaneity. Two clocks are placed at rest on the \(x^{\prime}\) axis of the primed frame, clock A at \(x^{\prime}=0\) and clock B at \(x^{\prime}=L_{0}\). They are therefore a...
-
A primed frame moves at \(V=(3 / 5) c\) relative to an unprimed frame. Just as their origins pass, clocks at the origins of both frames read zero, and a flashbulb explodes at that point. Later, the...
-
Two spaceships are approaching one another. According to observers in our frame, (a) the left-hand ship moves to the right at \((4 / 5) c\) and the right-hand ship moves to the left at \((3 / 5) c\)....
Study smarter with the SolutionInn App