Error with find(X) statement
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm trying to run a simple calculation to find the non-trivial columns of a unitary matrix. All the unitaries in this case are of the form:
[ 1 0 0 0,
0 a b 0,
0 c d 0,
0 0 0 1]
where a b c d form the 'non-trivial columns', in whatever columns.
Which is to say, if you sum the matrix either column wise or row wise, the sum must always equal 1, or be the non-trivial columns I'm trying to find. So the way I'm doing it is:
states=find(sum(UNITARY_MATRIX)~=1.0)
Which generally outputs something like:
Unitary number: 5
1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.8165 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.5774i
0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i -0.0000 + 0.5774i 0.0000 + 0.0000i -0.8165 + 0.0000i
sum of column values
1.0000 + 0.0000i 0.8165 + 0.5774i 1.0000 + 0.0000i -0.8165 - 0.5774i
Non trivial columns:
2 4
This is working very well for all the unitaries I'm checking, except for the following: (this is the output in the terminal)
Unitary number: 6
1.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i
0.0000 + 0.0000i 1.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i
-0.0000 + 0.0000i 0.0000 - 0.0000i 0.7071 - 0.0000i -0.7071 - 0.0000i
-0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.7071i 0.0000 - 0.7071i
sum of column values
1.0000 + 0.0000i 1.0000 + 0.0000i 0.7071 - 0.7071i -0.7071 - 0.7071i
Non trivial columns:
2 3 4
Any idea why this is happening? This is the only matrix this is happening with. Since clearly the non-trivial columns should be 3 and 4. Is this to do with how find(X) reads complex numbers?
댓글 수: 0
채택된 답변
Star Strider
2021년 7월 28일
Taking a wild guess, since the test is:
states=find(sum(UNITARY_MATRIX)~=1.0)
it is likely encountering floating-point approximation error, since the sum may not be exactly equal to 1.0, the criterion for the test.
Perhaps something like:
states=find(abs(1.0 - sum(UNITARY_MATRIX)) <= 1E-8)
or something similar (incorporating a range of some sort for the test) would work.
If this does not address what you want to do, I will delete my Answer.
.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!