Cody

# Problem 2801. geometric progression

Solution 3737718

Submitted on 19 Nov 2020 by PRM
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 = 4 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 1 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 2 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 3 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 4 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 5 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 6 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 7 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 8 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 9 truesequence = 2 8 32 128 512 2048 8192 32768 131072 524288 errorposition = 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 = 1 ratio = -4 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 1 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 2 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 3 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 4 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 5 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 6 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 7 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 8 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 9 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 10 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 11 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 12 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 13 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 14 truesequence = Columns 1 through 14 1 -4 16 -64 256 -1024 4096 -16384 65536 -262144 1048576 -4194304 16777216 -67108864 Column 15 268435456 errorposition = 15

### Community Treasure Hunt

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

Start Hunting!