Cody

# Problem 42798. Moving Product (Easy)

Solution 2360118

Submitted on 24 May 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
A = [1 2 3 4 5 6]; C = [6 24 60 120]; assert(isequal(moveprod(A,3),C))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test1 (line 3) assert(isequal(moveprod(A,3),C))

2   Fail
A = [1 2 3 4 5 6].'/6; C = [2 6 12 20 30].'/6^2; B = moveprod(A,2); assert(max(abs(B-C)) <= max(abs(C))*1e-12 && isequal(size(B),size(C)))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test2 (line 3) B = moveprod(A,2);

3   Fail
A = [-1 4 3 6 -2 2 0 1 2 -3 3 -6 -2 3 5]; C = [-2 0 3 12 6 6 0 -2 6 -15]; assert(isequal(moveprod(A,2),C))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test3 (line 6) assert(isequal(moveprod(A,2),C))

4   Fail
A = [-1 4 3 6 2 2 0 1 2 3 3 -6 -2 3 5]/pi; C = [-12 72 36 0 0 6 36 36 -30]/pi^3; B = moveprod(A,3,2); assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test4 (line 7) B = moveprod(A,3,2);

5   Fail
A = randi([-10,10],10,10,100); k = 5; dim = 3; B = moveprod(A,k,dim); szA = size(A); C = zeros(szA(1),szA(2),szA(3)-k+1); for m = 1:szA(1) for n = 1:szA(2) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k); end end assert(isequal(B,C))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test5 (line 3) B = moveprod(A,k,dim);

6   Fail
A = 20*rand(10,10,100)-10; k = 4; dim = 3; B = moveprod(A,k,dim); szA = size(A); C = zeros(szA(1),szA(2),szA(3)-k+1); for m = 1:szA(1) for n = 1:szA(2) C(m,n,:) = moveprod(squeeze(A(m,n,:)),k); end end C = C + 100*eps(C); assert(max(abs(B(:) - C(:))) <= max(abs(C(:)))*1e-12 && isequal(size(B),size(C)))

Error using movprod Not enough input arguments. Error in moveprod (line 2) B = movprod(varargin); Error in Test6 (line 3) B = moveprod(A,k,dim);

### Community Treasure Hunt

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

Start Hunting!