Cody

# Problem 44080. Construct a "diagAdiag" matrix

Solution 1436180

Submitted on 8 Feb 2018 by Andrew Dobrovolc
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
x = 3; y_correct = [1 2 6; 3 5 7;4 8 9]; assert(isequal(diagAdiag(x),y_correct))

count = 1 counter = 1 c = 1 vec = 1 count = 2 counter = 2 c = 2 vec = 2 3 count = 4 counter = 3 c = 3 vec = 4 5 6 count = 7 counter = 2 c = 4 vec = 7 8 count = 9 counter = 1 c = 5 vec = 9 y = 1 2 6 3 5 7 4 8 9

2   Pass
x = 4; y_correct = [1 2 6 7; 3 5 8 13;4 9 12 14;10 11 15 16]; assert(isequal(diagAdiag(x),y_correct))

count = 1 counter = 1 c = 1 vec = 1 count = 2 counter = 2 c = 2 vec = 2 3 count = 4 counter = 3 c = 3 vec = 4 5 6 count = 7 counter = 4 c = 4 vec = 7 8 9 10 count = 11 counter = 3 c = 5 vec = 11 12 13 count = 14 counter = 2 c = 6 vec = 14 15 count = 16 counter = 1 c = 7 vec = 16 y = 1 2 6 7 3 5 8 13 4 9 12 14 10 11 15 16

3   Pass
x = 5; y_correct = [1 2 6 7 15;3 5 8 14 16;4 9 13 17 22;10 12 18 21 23;11 19 20 24 25]; assert(isequal(diagAdiag(x),y_correct))

count = 1 counter = 1 c = 1 vec = 1 count = 2 counter = 2 c = 2 vec = 2 3 count = 4 counter = 3 c = 3 vec = 4 5 6 count = 7 counter = 4 c = 4 vec = 7 8 9 10 count = 11 counter = 5 c = 5 vec = 11 12 13 14 15 count = 16 counter = 4 c = 6 vec = 16 17 18 19 count = 20 counter = 3 c = 7 vec = 20 21 22 count = 23 counter = 2 c = 8 vec = 23 24 count = 25 counter = 1 c = 9 vec = 25 y = 1 2 6 7 15 3 5 8 14 16 4 9 13 17 22 10 12 18 21 23 11 19 20 24 25

4   Pass
x = 6; y_correct = [ 1 2 6 7 15 16; 3 5 8 14 17 26; 4 9 13 18 25 27; 10 12 19 24 28 33; 11 20 23 29 32 34; 21 22 30 31 35 36]; assert(isequal(diagAdiag(x),y_correct))

count = 1 counter = 1 c = 1 vec = 1 count = 2 counter = 2 c = 2 vec = 2 3 count = 4 counter = 3 c = 3 vec = 4 5 6 count = 7 counter = 4 c = 4 vec = 7 8 9 10 count = 11 counter = 5 c = 5 vec = 11 12 13 14 15 count = 16 counter = 6 c = 6 vec = 16 17 18 19 20 21 count = 22 counter = 5 c = 7 vec = 22 23 24 25 26 count = 27 counter = 4 c = 8 vec = 27 28 29 30 count = 31 counter = 3 c = 9 vec = 31 32 33 count = 34 counter = 2 c = 10 vec = 34 35 count = 36 counter = 1 c = 11 vec = 36 y = 1 2 6 7 15 16 3 5 8 14 17 26 4 9 13 18 25 27 10 12 19 24 28 33 11 20 23 29 32 34 21 22 30 31 35 36

5   Pass
x = 7; y_correct = [ 1 2 6 7 15 16 28; 3 5 8 14 17 27 29; 4 9 13 18 26 30 39; 10 12 19 25 31 38 40; 11 20 24 32 37 41 46; 21 23 33 36 42 45 47; 22 34 35 43 44 48 49]; assert(isequal(diagAdiag(x),y_correct))

count = 1 counter = 1 c = 1 vec = 1 count = 2 counter = 2 c = 2 vec = 2 3 count = 4 counter = 3 c = 3 vec = 4 5 6 count = 7 counter = 4 c = 4 vec = 7 8 9 10 count = 11 counter = 5 c = 5 vec = 11 12 13 14 15 count = 16 counter = 6 c = 6 vec = 16 17 18 19 20 21 count = 22 counter = 7 c = 7 vec = 22 23 24 25 26 27 28 count = 29 counter = 6 c = 8 vec = 29 30 31 32 33 34 count = 35 counter = 5 c = 9 vec = 35 36 37 38 39 count = 40 counter = 4 c = 10 vec = 40 41 42 43 count = 44 counter = 3 c = 11 vec = 44 45 46 count = 47 counter = 2 c = 12 vec = 47 48 count = 49 counter = 1 c = 13 vec = 49 y = 1 2 6 7 15 16 28 3 5 8 14 17 27 29 4 9 13 18 26 30 39 10 12 19 25 31 38 40 11 20 24 32 37 41 46 21 23 33 36 42 45 47 22 34 35 43 44 48 49

### Community Treasure Hunt

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

Start Hunting!