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
ian mohney
on 20 May 2015
Would be nice if we compare code speed instead of size.
goc3
on 18 Nov 2016
The test suite has been expanded.
omar malik
on 1 Jan 2018
nice
Solution Comments
Show commentsGroup

Indexing II
- 22 Problems
- 160 Finishers
- Getting the indices from a vector
- Symmetry of vector
- Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
- Count consecutive 0's in between values of 1
- Find last zero for each column
- Oh Zero Zero Zero!!!
- Create an index-powered vector
- Find nth maximum
- Decimation - Optimized for speed
- Unique values without using UNIQUE function
- Symmetry of vector
- Generate a vector like 1,2,2,3,3,3,4,4,4,4
- Create an n-by-n null matrix and fill with ones certain positions
- Implement a bubble sort technique and output the number of swaps required
- Create a vector whose elements depend on the previous element
- Set a diagonal
- Unique values without using UNIQUE function
- Generate a vector like 1,2,2,3,3,3,4,4,4,4
- Change the sign of even index entries of the reversed vector
- Decimation
- Insert zeros into vector
- Reference Index Number
- Determine the number of odd integers in a vector
- Max index of 3D array
- Finding peaks
- Getting the indices from a vector
Problem Recent Solvers712
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!