Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Matlab question. Pick a number, any number (actually, make it a positive integer). Now, lets play a game. If your number is

This is a Matlab question.

Pick a number, any number (actually, make it a positive integer). Now, lets 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. This is now known as the Collatz conjecture. Write a Matlab function file with structure function count = collatz(n) This function will take an input n (assume the user enters a positive integer) and will run through the Collatz process until a 1 is reached. It will output count, the number of iterations necessary to reach 1. As a test, your code should report that 112 iterations are necessary if we start with the number 2018. How many iterations are needed if we start with the following numbers?

(a) 26

(b) 27 (Why does 27 take so much longer than 26 and 28? Just one of those things.)

(c) 28

(d) 670,617,279 (this is the longest the process takes for any starting number less than 1 billion)

Now, look up the Collatz conjecture on the Wikipedia. There is a plot with red dots. Lets make that plot. Write a script file that repeatedly calls your function from part (a), runs through all integers from 1 to 10,000, and creates an array containing the number of steps required by the Collatz conjecture. Use a plot(num,steps,o) command at the end to generate the plot.

If possible please include code and answers. Thank You!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Did you add the logo at correct size and proportion?

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago

Question

How do members envision the ideal team?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago