Cody

Solution 2143781

Submitted on 28 Feb 2020 by Nikolaos Nikolaou
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
assert(isempty(mindiag([])))

2   Pass
x = randi(100); assert(isequal(mindiag(x),x))

3   Pass
x = randi(100,100,1); assert(isequal(mindiag(x),x(end:-1:1)'))

y = Columns 1 through 30 64 75 97 30 10 44 94 92 1 20 4 72 21 45 60 82 66 94 65 60 45 66 74 91 59 58 23 85 10 23 Columns 31 through 60 38 54 1 61 86 82 90 73 47 85 55 20 87 34 71 84 94 66 16 38 32 84 62 91 7 62 92 54 45 49 Columns 61 through 90 15 65 31 28 8 42 34 64 68 52 86 42 47 66 40 45 57 46 61 58 47 57 3 66 5 71 60 15 21 52 Columns 91 through 100 42 58 100 38 52 22 62 72 43 19

4   Pass
x = randi(100,1,100); assert(isequal(mindiag(x),x))

y = Columns 1 through 30 1 32 12 72 17 94 55 79 19 94 55 17 78 18 88 39 26 32 16 7 46 59 13 30 68 1 64 18 15 16 Columns 31 through 60 53 73 28 49 53 67 59 82 2 76 24 37 56 95 95 81 81 43 34 7 80 43 30 52 42 97 1 22 68 42 Columns 61 through 90 56 81 32 26 62 43 97 83 32 26 40 61 36 37 12 86 98 62 25 8 53 58 97 71 41 73 38 59 38 95 Columns 91 through 100 96 49 44 59 57 43 70 76 26 32

5   Pass
x = eye(2); assert(isequal(mindiag(x),[0 1 0]))

6   Pass
x = magic(3); assert(isequal(mindiag(x),[4 3 2 1 6]))

7   Pass
x = flipud(hankel(1:1000)); assert(isequal(mindiag(x),[1:1000,zeros(1,1000-1)]))

8   Pass
x = toeplitz(1:1000); assert(isequal(mindiag(x),[1000:-1:1,2:1000]))

9   Pass
N = randi(1000); x = fliplr(toeplitz(1:N)); y = ones(1,2*N-1); y(2:2:end) = 2; assert(isequal(mindiag(x),y))

10   Pass
x = magic(10); x = x(:,1:3); assert(isequal(mindiag(x),[11 10 12 6 5 24 76 4 19 80 7 1]))

11   Pass
x = hankel(-4:0,0:-2:-16); assert(isequal(mindiag(x),[0 -2 -4 -6 -8 -10 -12 -14 -16 -14 -12 -10 -8]))