Question: with using matlab 4. Let x, be any positive integer. Suppose that the following rules are used to generate a sequence of numbers based on

with using matlab with using matlab 4. Let x, be any positive integer. Suppose that

4. Let x, be any positive integer. Suppose that the following rules are used to generate a sequence of numbers based on XI. rule O: when Xx = 1, stop. if xx is even rule : Xk+1 (3xx + 1 if Xk is odd For example, x1 = 5 generates the sequence 5 16 8 4 2 1 and x = 11 generates the sequence 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1. (a) Write a function file to implement the foregoing rules, where the generated sequence is the output value of the function. Set the file name as 'mysequence.m'. (b) Compute and display the sequence with input, X; = 9. (c) Compute the length (number of elements) of the sequence in part (b) using the command length(mysequence(9)) (d) Write for loop in a script file to call the function created in part (a) to find the lengths of the sequences generated with the inputs, x1 = 1, x1 = 2, X = 3, ... until x1 = 100. (e) Expand the script file in part (d) to plot the graph of "length of sequences versus input values, x1, for x1 = 1,2,3,.. 100

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 Databases Questions!