1 | function Y = sign(X) |
---|
2 | % SIGN Signum function |
---|
3 | % (Quaternion overloading of standard Matlab function.) |
---|
4 | |
---|
5 | % Copyright © 2006 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
6 | % See the file : Copyright.m for further details. |
---|
7 | |
---|
8 | % This function is equivalent to unit(X), but we implement it by calling the Matlab function |
---|
9 | % using an isomorphic complex number. In the case where X is a complex quaternion we have to |
---|
10 | % resort to direct coding, and we call the quaternion unit function. We could choose to use |
---|
11 | % unit(X) in both cases, in which case sign(X) would simply be an alias for unit(X). |
---|
12 | error(nargchk(1, 1, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
13 | |
---|
14 | if isreal(X) |
---|
15 | |
---|
16 | % X is a real quaternion, and we compute the signum of an isomorphic complex number using |
---|
17 | % the standard Matlab sign function, then construct a quaternion with the same axis as the |
---|
18 | % original quaternion. |
---|
19 | |
---|
20 | Y = isoquaternion(sign(isocomplex(X)), X); |
---|
21 | else |
---|
22 | |
---|
23 | % X is a complex quaternion, and therefore we cannot use the method |
---|
24 | % above for real quaternions, because it is not possible to construct an |
---|
25 | % isomorphic complex number. We use instead the quaternion unit function. |
---|
26 | |
---|
27 | Y = unit(X); |
---|
28 | end; |
---|
29 | |
---|
30 | % Note that a fundamental design feature of the QTFM toolbox is that it should implement all the |
---|
31 | % standard Matlab functions and operators that have meaning in both the complex and quaternion |
---|
32 | % cases, so that complex code can be easily adapted to work with quaternion matrices. This is why |
---|
33 | % we provide the sign function, even though it has a synonym in the unit function. (Why we provide |
---|
34 | % the unit function is another issue.) |
---|