Question: Matlab code. Write a script that for any given integer n and computes the following: as long as the value of n is greater than

Matlab code. Write a script that for any given integer n and computes the following:
as long as the value of n is greater than 1(notice this will require while-loop),
replace n with (n/2) if the integer is even,
otherwise, replace n with (3n +1).
Make the code count the number of values in (or the length of) the sequence that results. For instance,
if n =10, the sequence of integers is 5,16,8,4,2,1, so the length is 6.
Then loop the script in such a way that it runs the algorithm for all n from 2 to 100, collects the respective sequence lengths into a vector.
Plot that vector.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!