Cody

# Problem 459. Sum of diagonal of a square matrix

Solution 1986098

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 = 34 34 34 34 x = 0 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 n = 18 34 34 34 y = 16 0 0 0 m = 18 34 34 34 x = 0 0 3 13 5 11 10 8 9 7 6 12 4 14 15 1 n = 18 32 34 34 y = 0 2 0 0 m = 18 32 34 34 x = 0 0 0 13 5 11 10 8 9 7 6 12 4 14 15 1 n = 18 32 31 34 y = 0 0 3 0 m = 18 32 31 34 x = 0 0 0 0 5 11 10 8 9 7 6 12 4 14 15 1 n = 18 32 31 21 y = 0 0 0 13

Assertion failed.

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

a = 5 m = 5 5 5 5 5 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 = 4 5 5 5 5 y = 1 0 0 0 0 m = 4 5 5 5 5 x = 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 4 4 5 5 5 y = 0 1 0 0 0 m = 4 4 5 5 5 x = 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 4 4 4 5 5 y = 0 0 1 0 0 m = 4 4 4 5 5 x = 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 4 4 4 4 5 y = 0 0 0 1 0 m = 4 4 4 4 5 x = 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n = 4 4 4 4 4 y = 0 0 0 0 1

Assertion failed.