Home > @quaternion > mpower.m

mpower

PURPOSE ^

MPOWER Raise quaternion to integer power

SYNOPSIS ^

function qp = mpower(q, p)

DESCRIPTION ^

MPOWER Raise quaternion to integer power

 Compound the quaternion with itself.  Invoked by means of the caret
 operator.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %MPOWER Raise quaternion to integer power
0002 %
0003 % Compound the quaternion with itself.  Invoked by means of the caret
0004 % operator.
0005 
0006 % Copyright (C) 1999-2008, by Peter I. Corke
0007 %
0008 % This file is part of The Robotics Toolbox for Matlab (RTB).
0009 %
0010 % RTB is free software: you can redistribute it and/or modify
0011 % it under the terms of the GNU Lesser General Public License as published by
0012 % the Free Software Foundation, either version 3 of the License, or
0013 % (at your option) any later version.
0014 %
0015 % RTB is distributed in the hope that it will be useful,
0016 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018 % GNU Lesser General Public License for more details.
0019 %
0020 % You should have received a copy of the GNU Leser General Public License
0021 % along with RTB.  If not, see <http://www.gnu.org/licenses/>.
0022 
0023 function qp = mpower(q, p)
0024 
0025     % check that exponent is an integer
0026     if (p - floor(p)) ~= 0,
0027         error('quaternion exponent must be integer');
0028     end
0029 
0030     qp = q;
0031 
0032     % multiply by itself so many times
0033     for i = 2:abs(p),
0034         qp = qp * q;
0035     end
0036 
0037     % if exponent was negative, invert it
0038     if p<0,
0039         qp = inv(qp);
0040     end

Generated on Sun 15-Feb-2009 18:09:29 by m2html © 2003