Cody

# Problem 2801. geometric progression

Solution 1214318

Submitted on 16 Jun 2017 by LY Cao
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
nterms = 10; term0 = randi(10) ratio = (-1)^randi(2)*randi(10) correctsequence = term0*ratio.^(0:nterms-1); for position = 1:nterms errorsequence = correctsequence; errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50); [errorposition, truesequence] = find_error(errorsequence); assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 1 at position %d', position); end

term0 = 2 ratio = -3 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 1 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 2 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 3 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 4 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 5 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 6 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 7 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 8 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 9 ans = -3 9 -27 81 -243 729 -2187 6561 -19683 59049 k = 10

2   Pass
nterms = 15; term0 = randi(10) ratio = (-1)^randi(2)*randi(10) correctsequence = term0*ratio.^(0:nterms-1); for position = 1:nterms errorsequence = correctsequence; errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50); [errorposition, truesequence] = find_error(errorsequence); assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 2 at position %d', position); end

term0 = 6 ratio = 8 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 1 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 2 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 3 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 4 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 5 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 6 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 7 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 8 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 9 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 10 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 11 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 12 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 13 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 14 ans = 1.0e+13 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0009 0.0069 0.0550 0.4398 3.5184 k = 15

### Community Treasure Hunt

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

Start Hunting!