필터 지우기
필터 지우기

the tranpose of transpose doed not equals the original matrix

조회 수: 4 (최근 30일)
Hantao Nie
Hantao Nie 2023년 10월 30일
편집: James Tursa 2024년 1월 23일
I find that on my data(see the attachment) ,the tranpose of transpose doed not equals the original matrix. This is my code. I donot understand why (a')' does not equals a. My matlab version is R2022a.
load("a.mat")
norm((a')' - a, 'fro')
ans = 140.4280

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 30일
이동: Walter Roberson 2023년 10월 30일
You have a broken sparse matrix, probably build by a third-party product, but possibly built by a broken mex file.
load("a.mat")
whos a
Name Size Bytes Class Attributes a 30084x1 157808 double sparse
at = a';
att = at';
whos a at att
Name Size Bytes Class Attributes a 30084x1 157808 double sparse at 1x30084 398472 double sparse att 30084x1 157808 double sparse
mask = att ~= a;
locs = find(mask, 1)
locs = 499
a(locs)
ans =
All zero sparse: 1×1
at(locs)
ans =
(1,1) -0.1000
att(locs)
ans =
(1,1) -0.1000
d = att - a;
max(d(:))
ans =
(1,1) 1
min(d(:))
ans =
(1,1) -1
nnz(imag(d))
ans = 0
  댓글 수: 2
James Tursa
James Tursa 2023년 10월 30일
편집: James Tursa 2023년 10월 30일
I see that Tim Davis's SPOK has been removed from the FEX. I will write a replacement and upload it when I get some free time, maybe this weekend. Should I call it SPOK for consistency in searches or give it a new name?
Walter Roberson
Walter Roberson 2023년 10월 30일
In view of tomorrow's date, perhaps it should be SPOOK ;-)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Tursa
James Tursa 2024년 1월 23일
편집: James Tursa 2024년 1월 23일
I finally finished my sparse matrix integrity checker. You can find it in the FEX under the name SAREK (I think you will be able to figure out the inside joke):
Here is what it reports for the posted matrix:
>> sarek(a)
SAREK -- Sparse Analyzer Real Et Komplex , by James Tursa
Compiled in version R2023a (with -R2018a option)
Running in version R2023a
Matrix is double ...
Matrix is real ...
M = 30084 >= 0 OK ...
N = 1 >= 0 OK ...
Nzmax = 9862 >= 1 OK ...
Jc[0] == 0 OK ...
Jc[N] = 9862 <= Nzmax = 9862 OK ...
Jc array OK ...
ERROR: There are 9861 Ir entries out of order or out of range
TO FIX: [M,N] = size(A); [I,J,V] = find(A); B = sparse(I,J,V,max(max(I),M),N);
All stored elements nonzero OK ...
There were ERRORS found in matrix!
ans =
9861
And if you plot the row indexes, you can see that the matrix was built in reverse order since they are all decreasing!
>> [I,J,V] = find(a);
>> plot(I)
After applying the recommended fix and re-plotting you can see that the row indexing order has been corrected:
>> [M,N] = size(a); [I,J,V] = find(a); B = sparse(I,J,V,max(max(I),M),N);
>> sarek(B)
SAREK -- Sparse Analyzer Real Et Komplex , by James Tursa
Compiled in version R2020a (with -R2018a option)
Running in version R2020a
Matrix is double ...
Matrix is real ...
M = 30084 >= 0 OK ...
N = 1 >= 0 OK ...
Nzmax = 9862 >= 1 OK ...
Jc[0] == 0 OK ...
Jc[N] = 9862 <= Nzmax = 9862 OK ...
Jc array OK ...
Ir array OK ...
All stored elements nonzero OK ...
All sparse integrity checks OK
ans =
0
>> [I,J,K] = find(B);
>> plot(I)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by