1 | function c = conj(a, F) |
---|
2 | % CONJ Quaternion conjugate. |
---|
3 | % (Quaternion overloading of Matlab standard function.) |
---|
4 | % |
---|
5 | % Implements three different conjugates: |
---|
6 | % |
---|
7 | % conj(X) or |
---|
8 | % conj(X, 'hamilton') returns the quaternion conjugate. |
---|
9 | % conj(X, 'complex') returns the complex conjugate. |
---|
10 | % conj(X, 'total') returns the 'total' conjugate equivalent to |
---|
11 | % conj(conj(X, 'complex'), 'hamilton') |
---|
12 | |
---|
13 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
14 | % See the file : Copyright.m for further details. |
---|
15 | |
---|
16 | error(nargchk(1, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
17 | |
---|
18 | if nargin == 1 |
---|
19 | F = 'hamilton'; % Supply the default parameter value. |
---|
20 | end |
---|
21 | |
---|
22 | if ~strcmp(F, 'hamilton') & ~strcmp(F, 'complex') & ~strcmp(F, 'total') |
---|
23 | error('Second parameter value must be ''hamilton'', ''complex'' or ''total''.') |
---|
24 | end |
---|
25 | |
---|
26 | switch F |
---|
27 | case 'hamilton' |
---|
28 | if ispure(a) |
---|
29 | c = -a; |
---|
30 | else |
---|
31 | c = quaternion(s(a), -x(a), -y(a), -z(a)); |
---|
32 | end |
---|
33 | case 'complex' |
---|
34 | if ispure(a) |
---|
35 | c = quaternion(conj(x(a)), conj(y(a)), conj(z(a))); |
---|
36 | else |
---|
37 | c = conj(s(a)) + conj(v(a), 'complex'); |
---|
38 | end |
---|
39 | case 'total' |
---|
40 | c = conj(conj(a, 'complex')); |
---|
41 | otherwise |
---|
42 | error('Bad value for second parameter.'); |
---|
43 | end |
---|