Why does this matrix contain different values depending on how it is accessed?
Show older comments
I am reading an mps file with the built-in matlab function mpsread. Specifically, I am trying to read the kb2 problem from the NETLIB database. The resulting left-hand side constraint matrix (that is sparse) exhibits some odd behavior. The following two commands result in different outcomes (the matrix's name is Aineq):
Aineq % shows that its entry on (15,41) is -0.31
Aineq(15,:) % shows that its entry on (15,41) is 0
Is this a common bug in using mpsread or is something else going on here?
EDIT: The following screenshot should correctly indicate what is going on:

Here, one would say that the first command would also have to include the entry found in row 15, column 41 that the second command does print. I have attached the matrix in a '.mat' file as well.
7 Comments
Guillaume
on 18 Sep 2017
Can you save your matrix in a mat file and attach that to your question? That would greatly help in finding out what is going on.
Walter Roberson
on 18 Sep 2017
I confirm your tests. I think somehow it is constructing a corrupt sparse matrix. Unfortunately the code at toolbox/optim/optim/private/readMPSfile.p is not readable so we can't see exactly what it is doing.
Walter Roberson
on 18 Sep 2017
Notice:
[r,c] = find(Aineq - full(Ain))
r =
10
11
12
15
c =
41
41
41
41
That should be impossible.
Ernst Roos
on 18 Sep 2017
Walter Roberson
on 18 Sep 2017
It should not matter what the (text) file has, sparse matrices are not supposed to have inconsistent values. I think it is a bug in the internal code for readMPSfile.p; I recommend you create a bug report.
DISP, SPY, FIND, all find this -0.31 value, converting to full and back to sparse eliminates the corruption. And it's not just a display issue (when indexed):
>> a = A(15,:) ; % Var a is corrupted as well
>> a
a =
(1,35) 98.500000000000000
(1,40) -0.810000000000000
>> a = A(15,41)
a =
All zero sparse: 1×1
>> a = A(14:15,41)
a =
(2,1) -0.310000000000000
Ernst Roos
on 19 Sep 2017
Accepted Answer
More Answers (0)
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!