Cody

# Problem 2801. geometric progression

Solution 3275403

Submitted on 19 Oct 2020 by Sibi
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 = 7 ratio = 4 d = 1.1667 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 0 1 1 1 1 1 1 1 1 1 e = 1 e = 1 d = 3.5714 4.4800 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 0 1 1 1 1 1 1 1 1 e = 2 e = 2 d = 4.0000 2.9286 5.4634 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 0 1 1 1 1 1 1 1 e = 3 e = 3 d = 4.0000 4.0000 3.8214 4.1869 4.0000 4.0000 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 0 1 1 1 1 1 1 e = 4 e = 4 d = 4.0000 4.0000 4.0000 3.9509 4.0497 4.0000 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 0 1 1 1 1 1 e = 5 e = 5 d = 4.0000 4.0000 4.0000 4.0000 3.9782 4.0219 4.0000 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 1 0 1 1 1 1 e = 6 e = 6 d = 4.0000 4.0000 4.0000 4.0000 4.0000 4.0070 3.9930 4.0000 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 1 1 0 1 1 1 e = 7 e = 7 d = 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 3.9998 4.0002 4.0000 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 1 1 1 0 1 1 e = 8 e = 8 d = 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0002 3.9998 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 1 1 1 1 0 1 e = 9 e = 9 d = 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 3.9999 r = 4 t = 7 28 112 448 1792 7168 28672 114688 458752 1835008 k = 1×10 logical array 1 1 1 1 1 1 1 1 1 0 e = 10 e = 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 = 9 ratio = -1 d = 0.3333 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 e = 1 e = 1 d = -6.3333 -0.1579 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 e = 2 e = 2 d = -1.0000 -2.7778 -0.3600 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 e = 3 e = 3 d = -1.0000 -1.0000 -3.5556 -0.2812 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 e = 4 e = 4 d = -1.0000 -1.0000 -1.0000 0.6667 1.5000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 e = 5 e = 5 d = -1.0000 -1.0000 -1.0000 -1.0000 2.3333 0.4286 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 e = 6 e = 6 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -4.1111 -0.2432 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 e = 7 e = 7 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -5.7778 -0.1731 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 e = 8 e = 8 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 0.6667 1.5000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 e = 9 e = 9 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -4.8889 -0.2045 -1.0000 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 e = 10 e = 10 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -2.2222 -0.4500 -1.0000 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 e = 11 e = 11 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 3.1111 0.3214 -1.0000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 e = 12 e = 12 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 2.0000 0.5000 -1.0000 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 e = 13 e = 13 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -6.3333 -0.1579 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 e = 14 e = 14 d = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -4.1111 r = -1 t = 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 -9 9 k = 1×15 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 e = 15 e = 15

### Community Treasure Hunt

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

Start Hunting!