Cody

# Problem 2585. How to reverse spdiags ?

Solution 1618925

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

ans = 3

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test1 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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

ans = 1

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test2 (line 2) assert(isequal(spdiags(inv_spdiags(b)),b))

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

ans = 2 3

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test3 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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

ans = 9

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test4 (line 2) assert(isequal(spdiags(inv_spdiags(y)),y))

5   Fail
x = spdiags(magic(5)); assert(isequal(spdiags(inv_spdiags(x)),x))

ans = 5

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test5 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

6   Fail
z = spdiags(ones(10)); assert(isequal(spdiags(inv_spdiags(z)),z))

ans = 10

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test6 (line 2) assert(isequal(spdiags(inv_spdiags(z)),z))

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

ans = 5

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test7 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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

ans = 2 3

Error using spdiags (line 95) For the syntax spdiags(B,d,m,n), the size of B must be min(m,n)-by-length(d). Error in inv_spdiags (line 19) spdiags(x,d,m,n) Error in Test8 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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