[37] | 1 | function C = adjoint(A, F) |
---|
| 2 | % ADJOINT Computes the adjoint of the quaternion matrix A. |
---|
| 3 | % |
---|
| 4 | % adjoint(A) or |
---|
| 5 | % adjoint(A, 'complex') returns a complex adjoint matrix. |
---|
| 6 | % adjoint(A, 'real') returns a real adjoint matrix. |
---|
| 7 | % |
---|
| 8 | % The definition of the adjoint matrix is not unique (several |
---|
| 9 | % permutations of the layout are possible). Note that if the |
---|
| 10 | % quaternion A is complexified, it is not possible to compute |
---|
| 11 | % a complex adjoint, since the complex values would have |
---|
| 12 | % complex real and imaginary parts. In this case, the real |
---|
| 13 | % adjoint will work, but its elements will be complex (!). |
---|
| 14 | |
---|
| 15 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 16 | % See the file : Copyright.m for further details. |
---|
| 17 | |
---|
| 18 | error(nargchk(1, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 19 | |
---|
| 20 | if nargin == 1 |
---|
| 21 | F = 'complex'; % Supply the default parameter value. |
---|
| 22 | end |
---|
| 23 | |
---|
| 24 | if ~strcmp(F, 'real') & ~strcmp(F, 'complex') |
---|
| 25 | error('Second parameter value must be ''real'' or ''complex''.') |
---|
| 26 | end |
---|
| 27 | |
---|
| 28 | % Extract the components of A. We use scalar() and not s() so that we |
---|
| 29 | % get zero if A is pure. |
---|
| 30 | |
---|
| 31 | R = scalar(A); X = x(A); Y = y(A); Z = z(A); |
---|
| 32 | |
---|
| 33 | if strcmp(F, 'complex') |
---|
| 34 | |
---|
| 35 | if all(all(imag(R) ~= 0)) | all(all(imag(X) ~= 0)) | ... |
---|
| 36 | all(all(imag(Y) ~= 0)) | all(all(imag(Z) ~= 0)) |
---|
| 37 | error('Cannot build a complex adjoint with complex elements: use ''real''.'); |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | % Reference: |
---|
| 41 | % |
---|
| 42 | % F. Z. Zhang, Quaternions and Matrices of Quaternions, |
---|
| 43 | % Linear Algebra and its Applications, 251, January 1997, 21-57. |
---|
| 44 | |
---|
| 45 | A1 = complex(R, X); A2 = complex(Y, Z); |
---|
| 46 | |
---|
| 47 | C = [[ A1, A2 ]; ... |
---|
| 48 | [-conj(A2), conj(A1)]]; |
---|
| 49 | |
---|
| 50 | else % F must be 'real', since we checked it above. |
---|
| 51 | |
---|
| 52 | % Reference: |
---|
| 53 | % |
---|
| 54 | % Todd A. Ell, 'Quaternion Notes', 1993-1999, unpublished, defines the |
---|
| 55 | % layout for a single quaternion. The extension to matrices of quaternions |
---|
| 56 | % follows easily in similar manner to Zhang above. |
---|
| 57 | % |
---|
| 58 | % An equivalent matrix representation for a single quaternion is noted |
---|
| 59 | % by Ward, J. P., 'Quaternions and Cayley numbers', Kluwer, 1997, p91. |
---|
| 60 | % It is the transpose of the representation used here. |
---|
| 61 | |
---|
| 62 | C = [[ R, X, Y, Z]; ... |
---|
| 63 | [-X, R, -Z, Y]; ... |
---|
| 64 | [-Y, Z, R, -X]; ... |
---|
| 65 | [-Z, -Y, X, R]]; |
---|
| 66 | end |
---|
| 67 | |
---|