source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/qtfm/@quaternion/log.m

Last change on this file was 37, checked in by (none), 15 years ago

Added original make3d

File size: 1.6 KB
Line 
1function Y = log(X)
2% LOG    Natural logarithm.
3% (Quaternion overloading of standard Matlab function.)
4
5% Copyright © 2005, 2006 Stephen J. Sangwine and Nicolas Le Bihan.
6% See the file : Copyright.m for further details.
7
8error(nargchk(1, 1, nargin)), error(nargoutchk(0, 1, nargout))
9
10if isreal(X)
11   
12    % X is a real quaternion, and we compute the logarithm of an isomorphic
13    % complex number using the standard Matlab log function, then construct
14    % a quaternion with the same axis as the original quaternion.
15   
16    Y = isoquaternion(log(isocomplex(X)), X);
17else
18   
19    % X is a complex quaternion, and therefore we cannot use the method
20    % above for real quaternions, because it is not possible to construct
21    % an isomorphic complex number. The algorithm used is documented in the
22    % appendix.
23
24    Y = quaternion(log(modsquared(X))./2, axis(X) .* angle(X));
25end;
26
27% Appendix.
28%
29% The calculation of log(X) is not difficult to derive, as follows.
30%
31% First note that exp(Y) = X (definition of logarithm). Then write
32% X in polar form as r .* exp(mu .* theta). Then we have:
33%
34% log(X) = Y = log(r) + log(exp(mu .* theta)) = log(r) + mu .* theta.
35%
36% Rather than calculate r = abs(X), we use modsquared because this
37% avoids calculating a square root. We compensate by halving log(r).
38% mu and theta are obtained using the axis and angle functions. Note
39% that we don't need to add the two results, since the first is a
40% real or complex value, and the second is a pure quaternion (real
41% or complex). Therefore we can compose them using the quaternion
42% constructor function.
Note: See TracBrowser for help on using the repository browser.