Cody

Problem 2801. geometric progression

Solution 3275343

Submitted on 19 Oct 2020
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   Fail
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 d = -0.2500 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 k = 3.7500 0 0 0 0 0 0 0 r = -4 t = 2 -8 32 -128 512 -2048 8192 -32768 131072 -524288 k = 1×10 logical array 0 1 1 1 1 1 1 1 1 1 e = 1 e = 1 d = 1 16 -4 -4 -4 -4 -4 -4 -4 k = -15 20 0 0 0 0 0 0 r = -4 t = 2 -8 32 -128 512 -2048 8192 -32768 131072 -524288 k = 1×10 logical array 1 0 1 1 1 1 1 1 1 1 e = 2 e = 2 d = -4.0000 0.2500 64.0000 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 k = -4.2500 -63.7500 68.0000 0 0 0 0 0 r = -4 t = 2 -8 32 -128 512 -2048 8192 -32768 131072 -524288 k = 1×10 logical array 1 1 0 1 1 1 1 1 1 1 e = 3 e = 3 d = -4.0000 -4.0000 -4.3750 -3.6571 -4.0000 -4.0000 -4.0000 -4.0000 -4.0000 k = 0 0.3750 -0.7179 0.3429 0 0 0 0 r = -4 t = 2 -8 32 -128 512 -2048 8192 -32768 131072 -524288 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.9062 -4.0960 -4.0000 -4.0000 -4.0000 -4.0000 k = 0 0 -0.0938 0.1898 -0.0960 0 0 0 r = -4 t = 1.0e+05 * 0.0000 -0.0001 0.0003 -0.0013 0.0050 -0.0200 0.0800 -0.3200 1.2800 -5.1200 k = 1×10 logical array 0 0 0 0 1 0 0 0 0 0 e = 1 2 3 4 6 7 8 9 10 e = 1

failed test 1 at position 5

2   Fail
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 = -9 d = -3.6000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 -9.0000 k = 5.4000 0 0 0 0 0 0 0 0 0 0 0 0 r = -9 t = 1.0e+14 * 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0002 -0.0019 0.0169 -0.1525 1.3726 k = 1×15 logical array 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 e = 1 2 e = 1

failed test 2 at position 1

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!