Why does this matrix contain different values depending on how it is accessed?
이전 댓글 표시
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
Guillaume
2017년 9월 18일
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
2017년 9월 18일
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
2017년 9월 18일
Notice:
[r,c] = find(Aineq - full(Ain))
r =
10
11
12
15
c =
41
41
41
41
That should be impossible.
Ernst Roos
2017년 9월 18일
Walter Roberson
2017년 9월 18일
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
2017년 9월 19일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!