Cody

Problem 2801. geometric progression

Solution 3115471

Submitted on 8 Oct 2020 by kaatil_coder
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 = 9 ratio = 2 id = 1 ts = 9 18 36 72 144 288 576 1152 2304 4608 ep = 1 s = -33 18 36 72 144 288 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 1 ep = 2 s = 9 33 36 72 144 288 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 2 ep = 3 s = 9 18 27 72 144 288 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 3 ep = 4 s = 9 18 36 96 144 288 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 4 ep = 5 s = 9 18 36 72 162 288 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 5 ep = 6 s = 9 18 36 72 144 239 576 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 6 ep = 7 s = 9 18 36 72 144 288 588 1152 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 7 ep = 8 s = 9 18 36 72 144 288 576 1139 2304 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 8 ep = 9 s = 9 18 36 72 144 288 576 1152 2335 4608 ts = 9 18 36 72 144 288 576 1152 2304 4608 id = 9 ep = 10 s = 9 18 36 72 144 288 576 1152 2304 4574 ts = 9 18 36 72 144 288 576 1152 2304 4608

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 = 4 ratio = 6 id = 1 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ep = 1 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 1 ep = 2 s = 1.0e+11 * 0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 2 ep = 3 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 3 ep = 4 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 4 ep = 5 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 5 ep = 6 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 6 ep = 7 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 7 ep = 8 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 8 ep = 9 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 9 ep = 10 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 10 ep = 11 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 11 ep = 12 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 12 ep = 13 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 13 ep = 14 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 id = 14 ep = 15 s = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346 ts = 1.0e+11 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 0.0024 0.0145 0.0871 0.5224 3.1346

Suggested Problems

More from this Author9

Community Treasure Hunt

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

Start Hunting!