Error with find(X) statement
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!