Cody

# Problem 459. Sum of diagonal of a square matrix

Solution 1986103

Submitted on 22 Oct 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 = magic(4); y_correct = sum(diag(x)); assert(isequal(your_fcn_name(x),y_correct))

a = 4 m = 136 x = 0 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 n = 120 y = 16 m = 120 x = 0 2 3 13 5 0 10 8 9 7 6 12 4 14 15 1 n = 109 y = 11 m = 109 x = 0 2 3 13 5 0 10 8 9 7 0 12 4 14 15 1 n = 103 y = 6 m = 103 x = 0 2 3 13 5 0 10 8 9 7 0 12 4 14 15 0 n = 102 y = 1

Assertion failed.

2   Fail
x = ones(5); y_correct = sum(diag(x)); assert(isequal(your_fcn_name(x),y_correct))

a = 5 m = 25 x = 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 24 y = 1 m = 24 x = 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 23 y = 1 m = 23 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 n = 22 y = 1 m = 22 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 n = 21 y = 1 m = 21 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 n = 20 y = 1

Assertion failed.