Cody

# Problem 2585. How to reverse spdiags ?

Solution 1618929

Submitted on 29 Aug 2018 by HH
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 = spdiags([1 2 3;4 5 6;7 8 9]); assert(isequal(spdiags(inv_spdiags(x)),x))

ans = (1,1) 1 (2,1) 4 (3,1) 7 (1,2) 2 (2,2) 5 (3,2) 8 (1,3) 3 (2,3) 6 (3,3) 9

2   Pass
b = spdiags(eye(10)); assert(isequal(spdiags(inv_spdiags(b)),b))

3   Pass
x = spdiags([1 2 3;4 5 6]); assert(isequal(spdiags(inv_spdiags(x)),x))

ans = (1,1) 1 (2,1) 4 (1,2) 2 (2,2) 5 (1,3) 3 (2,3) 6

4   Pass
y = spdiags(magic(9)); assert(isequal(spdiags(inv_spdiags(y)),y))

ans = (1,1) 47 (2,1) 57 (3,1) 67 (4,1) 77 (5,1) 6 (6,1) 16 (7,1) 26 (8,1) 36 (9,1) 37 (1,2) 58 (2,2) 68 (3,2) 78 (4,2) 7 (5,2) 17 (6,2) 27 (7,2) 28 (8,2) 38 (9,2) 48 (1,3) 69 (2,3) 79 (3,3) 8 (4,3) 18 (5,3) 19 (6,3) 29 (7,3) 39 (8,3) 49 (9,3) 59 (1,4) 80 (2,4) 9 (3,4) 10 (4,4) 20 (5,4) 30 (6,4) 40 (7,4) 50 (8,4) 60 (9,4) 70 (1,5) 1 (2,5) 11 (3,5) 21 (4,5) 31 (5,5) 41 (6,5) 51 (7,5) 61 (8,5) 71 (9,5) 81 (1,6) 12 (2,6) 22 (3,6) 32 (4,6) 42 (5,6) 52 (6,6) 62 (7,6) 72 (8,6) 73 (9,6) 2 (1,7) 23 (2,7) 33 (3,7) 43 (4,7) 53 (5,7) 63 (6,7) 64 (7,7) 74 (8,7) 3 (9,7) 13 (1,8) 34 (2,8) 44 (3,8) 54 (4,8) 55 (5,8) 65 (6,8) 75 (7,8) 4 (8,8) 14 (9,8) 24 (1,9) 45 (2,9) 46 (3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,9) 1 (6,9) 1 (7,9) 1 (8,9) 1 (9,9) 1 (10,9) 1 (1,10) 1 (2,10) 1 (3,10) 1 (4,10) 1 (5,10) 1 (6,10) 1 (7,10) 1 (8,10) 1 (9,10) 1 (10,10) 1

7   Pass
x = spdiags(randi(10,5)); assert(isequal(spdiags(inv_spdiags(x)),x))

ans = (1,1) 8 (2,1) 10 (3,1) 1 (4,1) 2 (5,1) 10 (1,2) 10 (2,2) 10 (3,2) 3 (4,2) 8 (5,2) 2 (1,3) 1 (2,3) 9 (3,3) 9 (4,3) 10 (5,3) 4 (1,4) 8 (2,4) 9 (3,4) 9 (4,4) 3 (5,4) 7 (1,5) 4 (2,5) 7 (3,5) 7 (4,5) 4 (5,5) 8

8   Pass
x = spdiags(randi(5,[3 2])); assert(isequal(spdiags(inv_spdiags(x)),x))

ans = (1,1) 2 (2,1) 3 (3,1) 1 (1,2) 5 (2,2) 1 (3,2) 3

9   Pass
a = spdiags(zeros(5)); assert(isequal(spdiags(inv_spdiags(a)),a))