1 ## Copyright (C) 2010, 2011 Lukas F. Reichlin
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
4 ## This program is free software: you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation, either version 3 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ## Power operator of quaternions. Used by Octave for "q.^x".
19 ## Exponent x can be scalar or of appropriate size.
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
25 function a = power (a, b)
27 if (isa (b, "quaternion")) # exponent is a quaternion
28 a = exp (log (a) .* b); # a could be real, but log doesn't care
30 error ("quaternion:invalidArgument", "quaternion: power: invalid exponent");
31 elseif (b == -1) # special case for ldivide and rdivide
32 norm2 = norm2 (a); # a is quaternion because b is not,
33 a.w = a.w ./ norm2; # otherwise octave wouldn't call
34 a.x = -a.x ./ norm2; # quaternion's power operator.
37 else # exponent is real
40 th = acos (a.w ./ na);
43 a.w = nab .* cos (b.*th);
44 a.x = (a.x ./ nv) .* nab .* snt;
45 a.y = (a.y ./ nv) .* nab .* snt;
46 a.z = (a.z ./ nv) .* nab .* snt;