Line | |
---|
1 | function tf = isunitary(A, tol) |
---|
2 | % ISUNITARY True if the given matrix is unitary to within the tolerance |
---|
3 | % given (optionally) by the second parameter. |
---|
4 | |
---|
5 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
6 | % See the file : Copyright.m for further details. |
---|
7 | |
---|
8 | error(nargchk(1, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
9 | |
---|
10 | if nargin == 1 |
---|
11 | tol = 16 .* eps; % The tolerance was not specified, supply a default. |
---|
12 | end |
---|
13 | |
---|
14 | [r, c] = size(A); |
---|
15 | |
---|
16 | if r ~= c |
---|
17 | error('A non-square matrix cannot be unitary.'); |
---|
18 | end |
---|
19 | |
---|
20 | % The method used is to subtract a quaternion identity matrix from A * A'. |
---|
21 | % The result should be almost zero. To compare it against the tolerance, |
---|
22 | % we add the moduli of the four components. This is guaranteed to give a |
---|
23 | % real result, even when A is a complexified quaternion matrix. |
---|
24 | |
---|
25 | D = A * A' - quaternion(eye(r)); |
---|
26 | |
---|
27 | tf = all(all(abs(s(D)) + abs(x(D)) + abs(y(D)) + abs(z(D)) < tol)); |
---|
Note: See
TracBrowser
for help on using the repository browser.