[37] | 1 | function n = det(X, d) |
---|
| 2 | % DET Determinant. |
---|
| 3 | % (Quaternion overloading of standard Matlab function, with differences.) |
---|
| 4 | % |
---|
| 5 | % The second parameter may be: |
---|
| 6 | % |
---|
| 7 | % 'Moore' The determinant is the product of the eigenvalues of X. |
---|
| 8 | % 'Dieudonn' or |
---|
| 9 | % 'Dieudonne' The determinant is the product of the singular values of X. |
---|
| 10 | % 'Study' The determinant is the determinant of the adjoint of X. If X |
---|
| 11 | % is a real quaternion matrix, the complex adjoint is used. If |
---|
| 12 | % X is a complexified quaternion matrix, the real adjoint is |
---|
| 13 | % used. |
---|
| 14 | % |
---|
| 15 | % The Moore determinant is the only one which can be negative or complex. |
---|
| 16 | % but it cannot be calculated for a non-Hermitian matrix since there is |
---|
| 17 | % currently no way to calculate the eigenvalues of a non-Hermitian matrix. |
---|
| 18 | % The Study determinant is the square of the Dieudonn determinant and is |
---|
| 19 | % much faster to calculate, but it may not be accurately real, whereas the |
---|
| 20 | % Dieudonn determinant is real by definition. |
---|
| 21 | % |
---|
| 22 | % For the moment, there is no default value for the second parameter. This |
---|
| 23 | % may be changed if a way is found to calculate the Moore determinant for |
---|
| 24 | % non-Hermitian matrices (Moore will be the default). |
---|
| 25 | |
---|
| 26 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 27 | % See the file : Copyright.m for further details. |
---|
| 28 | |
---|
| 29 | % References: |
---|
| 30 | % |
---|
| 31 | % Helmer Aslaksen, 'Quaternionic Determinants', |
---|
| 32 | % The Mathematical Intelligencer, 18 (3), 1996, 56-65. |
---|
| 33 | % [Reprinted in 'Mathematical Conversation: Selections from |
---|
| 34 | % The Mathematical Intelligencer', Robin Williams and Jeremy Gray (eds.), |
---|
| 35 | % 142-156, Springer-Verlag, 2001.] |
---|
| 36 | % |
---|
| 37 | % F. Z. Zhang, Quaternions and Matrices of Quaternions, |
---|
| 38 | % Linear Algebra and its Applications, 251, January 1997, 21-57. [see p47] |
---|
| 39 | |
---|
| 40 | % Note: Aslaksen defines the complex adjoint matrix differently to Zhang |
---|
| 41 | % but the two definitions are in fact equivalent, since Aslaksen defines |
---|
| 42 | % the Cayley_Dickson form with j on the left, whereas Zhang puts j on the |
---|
| 43 | % right. |
---|
| 44 | |
---|
| 45 | error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 46 | |
---|
| 47 | [r,c] = size(X); |
---|
| 48 | |
---|
| 49 | if r ~= c |
---|
| 50 | error('Matrix must be square.'); |
---|
| 51 | end |
---|
| 52 | |
---|
| 53 | % For the moment, there is no default, and the error check on nargin |
---|
| 54 | % above requires 2 arguments. If the restriction to Hermitian matrices |
---|
| 55 | % can be removed, this code can be reinstated, and the error check |
---|
| 56 | % alterered to 1, 2. |
---|
| 57 | % |
---|
| 58 | % if nargin == 1 |
---|
| 59 | % d = 'Moore'; % Set the default value if none was supplied. |
---|
| 60 | % end |
---|
| 61 | |
---|
| 62 | switch d |
---|
| 63 | case {'Dieudonn', 'Dieudonne'} |
---|
| 64 | |
---|
| 65 | % The Dieudonn determinant is defined by diagonalising the matrix. |
---|
| 66 | % Since the determinant of a product is the product of the determinants |
---|
| 67 | % and the determinant of a unitary matrix is 1, we can calculate the |
---|
| 68 | % Dieudonn determinant using the SVD (it is the product of the |
---|
| 69 | % singular values). |
---|
| 70 | |
---|
| 71 | n = prod(svd(X)); |
---|
| 72 | case 'Study' |
---|
| 73 | |
---|
| 74 | % The Study determinant is defined in terms of the adjoint, but we |
---|
| 75 | % cannot compute a complex adjoint for a complexified quaternion |
---|
| 76 | % matrix - we must use a real adjoint. Of course, Study did not |
---|
| 77 | % consider this, so what is coded below is an extension of his idea. |
---|
| 78 | % The Study determinant is real for a quaternion matrix, and complex |
---|
| 79 | % for a complexified quaternion matrix. The Study determinant is the |
---|
| 80 | % square of the Dieudonné determinant. |
---|
| 81 | |
---|
| 82 | if any(any(imag(X) ~= 0)) |
---|
| 83 | n = det(adjoint(X, 'real')); |
---|
| 84 | else |
---|
| 85 | n = det(adjoint(X)); |
---|
| 86 | end |
---|
| 87 | case 'Moore' |
---|
| 88 | |
---|
| 89 | % The Moore determinant is the product of the eigenvalues, but the |
---|
| 90 | % matrix must be Hermitian (implementation restriction on the eig |
---|
| 91 | % function which may be removed in the future). |
---|
| 92 | |
---|
| 93 | if ishermitian(X) |
---|
| 94 | n = prod(eig(X)); |
---|
| 95 | else |
---|
| 96 | error('Cannot compute Moore determinant of a non-Hermitian matrix.') |
---|
| 97 | end |
---|
| 98 | otherwise |
---|
| 99 | error(['Unrecognized second parameter, ', d, ' determinant unknown.']); |
---|
| 100 | end |
---|
| 101 | |
---|