Cody

Problem 2585. How to reverse spdiags ?

Solution 2909230

Submitted on 4 Sep 2020
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))

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

Error using reshape Size arguments must be real integers. Error in inv_spdiags (line 3) y = reshape(a(a~=0),numel(a(a~=0))^0.5,numel(a(a~=0))^0.5); 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))

Error using reshape Size arguments must be real integers. Error in inv_spdiags (line 3) y = reshape(a(a~=0),numel(a(a~=0))^0.5,numel(a(a~=0))^0.5); Error in Test3 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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

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

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

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

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

Error using reshape Size arguments must be real integers. Error in inv_spdiags (line 3) y = reshape(a(a~=0),numel(a(a~=0))^0.5,numel(a(a~=0))^0.5); Error in Test8 (line 2) assert(isequal(spdiags(inv_spdiags(x)),x))

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

Assertion failed.

Suggested Problems

More from this Author43

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!