Cody

Problem 44844. Moving average

Solution 2064587

Submitted on 20 Dec 2019
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
x = 0:7; y = 2*x; w = 3; ys = movingAverage(x,y,w); assert(isequal(ys,y))

ys = 0 14

Assertion failed.

2   Fail
x = 0:9; y = exp(0.1*x)'; w = 4; ys_correct = [1.0000 1.1089 1.2337 1.3770 1.5420 1.7042 1.8588 2.0339 2.2330 2.4596]; ys = movingAverage(x,y,w); assert(norm(ys_correct-ys)<.001)

ys = 1.0000 1.1089 1.2255 1.3544 1.4968 1.6542 1.8282 2.0205 2.2330 2.4596

Assertion failed.

3   Fail
x = 0:6; y = sin(x); w = 1; ys_correct = [0 0.5836 0.6306 0.0979 -0.5249 -0.6650 -0.2794]; ys = movingAverage(x,y,w); assert(norm(ys_correct-ys)<.001)

ys = 0 -0.2794

Matrix dimensions must agree. Error in Test3 (line 6) assert(norm(ys_correct-ys)<.001)

4   Fail
x = 3:11; y = log(x)'; w = 6; ys_correct = [1.0986 1.3648 1.5664 1.7298 1.8677 2.0463 2.1846 2.2992 2.3979]; ys = movingAverage(x,y,w); assert(norm(ys_correct-ys)<.001)

ys = 1.0986 1.3648 1.5958 1.7824 1.9390 2.0742 2.1931 2.2992 2.3979

Assertion failed.