Cody

Problem 2801. geometric progression

Solution 2746375

Submitted on 27 Jul 2020 by Rachelle Lee
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 = 4 ratio = 3 ari = 3 errorsequence = 4 12 36 108 324 972 2916 8748 26244 78732 errorposition = 1 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 errorsequence = 4 12 36 108 324 972 2916 8748 26244 78732 errorposition = 2 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732 ari = 3 truesequence = 4 12 36 108 324 972 2916 8748 26244 78732

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 = 3 ratio = 1 ari = 1 errorsequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 errorposition = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 errorsequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 errorposition = 2 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ari = 1 truesequence = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

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!