Problem 888. Create a vector whose elements depend on the previous element
The idea is to create a vector A whose elements depend on the previous element : A(i+1) = 2*A(i)+1
2 Inputs:
- A : The first value of the vector
- iterations : The number of iterations
1 Output:
- A a vector with iterations+1 elements such as the i+1 element depend on the previous element as follows :
A(i+1) = 2*A(i)+1
Example :
A = 1; iterations = 4;
The expected output vector has 5 elements :
A = [1 3 7 15 31]
A(2) =3 because A(2) =2*A(1)+1 = 2*1+1 = 3
A(3) = 7 because A(3) =2*A(2)+1 ...
Solution Stats
Problem Comments
-
3 Comments
Would be nice if we compare code speed instead of size.
The test suite has been expanded.
nice
Solution Comments
Show commentsProblem Recent Solvers767
Suggested Problems
-
Find the numeric mean of the prime numbers in a matrix.
9114 Solvers
-
Return a list sorted by number of occurrences
2885 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
552 Solvers
-
Vectorize the digits of an Integer
334 Solvers
-
Permute diagonal and antidiagonal
493 Solvers
More from this Author30
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!