Cody

# Problem 2094. Sum of diagonals elements of a matrix

Solution 936209

Submitted on 14 Aug 2016 by Martin C.
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 = [1 2 3;4 5 6; 7 8 9;]; y_correct = 25; assert(isequal(DiagSum(x),y_correct));

s = 0 l = 3 s = 1 s = 4 s = 9 s = 14 s = 23 s = 30 y = 25

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

s = 0 l = 5 s = 1 s = 6 s = 13 s = 22 s = 35 s = 48 s = 67 s = 84 s = 109 s = 130 y = 117

3   Pass
x = ones(7); y_correct = 13; assert(isequal(DiagSum(x),y_correct));

s = 0 l = 7 s = 1 s = 2 s = 3 s = 4 s = 5 s = 6 s = 7 s = 8 s = 9 s = 10 s = 11 s = 12 s = 13 s = 14 y = 13

4   Pass
x = magic(9); y_correct = 697; assert(isequal(DiagSum(x),y_correct));

s = 0 l = 9 s = 47 s = 92 s = 160 s = 204 s = 212 s = 255 s = 275 s = 317 s = 358 s = 399 s = 461 s = 501 s = 575 s = 614 s = 628 s = 666 s = 701 s = 738 y = 697