1 | function Y = exp(X) |
---|
2 | % EXP Exponential |
---|
3 | % (Quaternion overloading of standard Matlab function.) |
---|
4 | |
---|
5 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
6 | % See the file : Copyright.m for further details. |
---|
7 | |
---|
8 | % Modified 21 September 2005 to handle undefined axis correctly. |
---|
9 | |
---|
10 | error(nargchk(1, 1, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
11 | |
---|
12 | if ispure(X) |
---|
13 | |
---|
14 | % X is a pure quaternion (array). Each element is the product of an |
---|
15 | % axis and an angle (either or both may be complex), and we need to |
---|
16 | % separate them out in order to compute the hypercomplex exponential |
---|
17 | % using de Moivre's formula. If the modulus of any element of X is zero |
---|
18 | % or very small, the axis will be undefined, and we have to take care |
---|
19 | % to handle this without returning NaNs, since although the axis is |
---|
20 | % undefined, the exponential is not. |
---|
21 | |
---|
22 | theta = abs(X); % Since theta could be complex, we need |
---|
23 | undefined = abs(theta) < eps; % abs() again here to compare with eps. |
---|
24 | |
---|
25 | cc = cos(theta); % If theta is complex, the cosine and sine will yield |
---|
26 | ss = sin(theta); % cosh and I.*sinh of theta. |
---|
27 | |
---|
28 | theta(undefined) = 1; % This prevents divide by zero in the element |
---|
29 | % positions where the axis is undefined. |
---|
30 | |
---|
31 | a = X ./ theta; % This is equivalent to axis(X) but without warnings |
---|
32 | % about undefined axis because values of theta less |
---|
33 | % than eps have been replaced with 1. This means the |
---|
34 | % values at positions corresponding to undefined axis |
---|
35 | % are incorrect, since we have copied the (small) value |
---|
36 | % from X unmodified. However, these values will be |
---|
37 | % multiplied by a zero or very small (less than eps) |
---|
38 | % sine value below, so are harmless. |
---|
39 | |
---|
40 | Y = cc + a .* ss; |
---|
41 | else |
---|
42 | |
---|
43 | % X is a full quaternion (array). We use a recursive call to compute |
---|
44 | % the exponential of the vector part, and the standard Matlab function |
---|
45 | % to compute the exponential of the scalar part (which may be complex). |
---|
46 | % The result is the elementwise product of the two. |
---|
47 | |
---|
48 | Y = exp(s(X)) .* exp(v(X)); |
---|
49 | end |
---|