Cody

# Problem 888. Create a vector whose elements depend on the previous element

Solution 2894207

Submitted on 31 Aug 2020 by Jeong Suong Yang
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
A = 1; iterations = 4; y_correct = [1 3 7 15 31]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 1 3 1 1 1 y = 1 3 7 1 1 y = 1 3 7 15 1 y = 1 3 7 15 31

2   Pass
A = 1; iterations = 10; y_correct = [1 3 7 15 31 63 127 255 511 1023 2047]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 1 3 1 1 1 1 1 1 1 1 1 y = 1 3 7 1 1 1 1 1 1 1 1 y = 1 3 7 15 1 1 1 1 1 1 1 y = 1 3 7 15 31 1 1 1 1 1 1 y = 1 3 7 15 31 63 1 1 1 1 1 y = 1 3 7 15 31 63 127 1 1 1 1 y = 1 3 7 15 31 63 127 255 1 1 1 y = 1 3 7 15 31 63 127 255 511 1 1 y = 1 3 7 15 31 63 127 255 511 1023 1 y = 1 3 7 15 31 63 127 255 511 1023 2047

3   Pass
A = 2; iterations = 10; y_correct = [2 5 11 23 47 95 191 383 767 1535 3071]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 2 5 2 2 2 2 2 2 2 2 2 y = 2 5 11 2 2 2 2 2 2 2 2 y = 2 5 11 23 2 2 2 2 2 2 2 y = 2 5 11 23 47 2 2 2 2 2 2 y = 2 5 11 23 47 95 2 2 2 2 2 y = 2 5 11 23 47 95 191 2 2 2 2 y = 2 5 11 23 47 95 191 383 2 2 2 y = 2 5 11 23 47 95 191 383 767 2 2 y = 2 5 11 23 47 95 191 383 767 1535 2 y = 2 5 11 23 47 95 191 383 767 1535 3071

4   Pass
A = 3; iterations = 10; y_correct = [3 7 15 31 63 127 255 511 1023 2047 4095]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 3 7 3 3 3 3 3 3 3 3 3 y = 3 7 15 3 3 3 3 3 3 3 3 y = 3 7 15 31 3 3 3 3 3 3 3 y = 3 7 15 31 63 3 3 3 3 3 3 y = 3 7 15 31 63 127 3 3 3 3 3 y = 3 7 15 31 63 127 255 3 3 3 3 y = 3 7 15 31 63 127 255 511 3 3 3 y = 3 7 15 31 63 127 255 511 1023 3 3 y = 3 7 15 31 63 127 255 511 1023 2047 3 y = 3 7 15 31 63 127 255 511 1023 2047 4095

5   Pass
A = 5; iterations = 10; y_correct = [5 11 23 47 95 191 383 767 1535 3071 6143]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 5 11 5 5 5 5 5 5 5 5 5 y = 5 11 23 5 5 5 5 5 5 5 5 y = 5 11 23 47 5 5 5 5 5 5 5 y = 5 11 23 47 95 5 5 5 5 5 5 y = 5 11 23 47 95 191 5 5 5 5 5 y = 5 11 23 47 95 191 383 5 5 5 5 y = 5 11 23 47 95 191 383 767 5 5 5 y = 5 11 23 47 95 191 383 767 1535 5 5 y = 5 11 23 47 95 191 383 767 1535 3071 5 y = 5 11 23 47 95 191 383 767 1535 3071 6143

6   Pass
A = 7; iterations = 8; y_correct = [7 15 31 63 127 255 511 1023 2047]; assert(isequal(your_fcn_name(A,iterations),y_correct))

y = 7 15 7 7 7 7 7 7 7 y = 7 15 31 7 7 7 7 7 7 y = 7 15 31 63 7 7 7 7 7 y = 7 15 31 63 127 7 7 7 7 y = 7 15 31 63 127 255 7 7 7 y = 7 15 31 63 127 255 511 7 7 y = 7 15 31 63 127 255 511 1023 7 y = 7 15 31 63 127 255 511 1023 2047

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!