Library quaternion implements the constructors and methods of class quaternion. Basic arithmetic operators and functions are overloaded to support expressions with the same syntax as for numbers and matrices.
Quaternions are numbers similar to complex numbers, but with four components instead
of two. The unit imaginary parts are named
It follows that the product of two quaternions is not commutative.
The following statement makes available functions defined in quaternion:
use quaternion
Polynom object constructor.
a = quaternion a = quaternion(x) a = quaternion(z) a = quaternion(w, x, y, z)
With a real argument, quaternion(x) creates a quaternion object whose real part is x and imaginary parts are 0. With a complex argument, quaternion(z) creates the quaternion object real(z)+i*imag(z).
With four real arguments, quaternion(w,x,y,z) creates the quaternion object w+i*x+j*y+k*z.
In all cases, the arguments may be scalars or vectors of the same length.
Without argument, quaternion returns a the null quaternion object.
The following operators and functions may be used with quaternion arguments. They all operate on each element of vectors separately.
+ | plus | addition |
- | minus | subtraction |
* | mtimes | product |
/ | mrdivide | right division |
\ | mldivide | left division |
- | uminus | negative |
+ | uplus | unary plus (no operation) |
() | subsref | indexing |
norm | quaternion norm (sum of squares) | |
abs | absolute value | |
conj | quaternion conjugate | |
sign | normalization | |
inv | inverse |
q = quaternion(1,2,3,4) 1 = 1+2i+3j+4k q = 3 * p^2 + 8 q = 27x^8+18x^6-72x^5+39x^4-24x^3+60x^2-48x+20
Display a quaternion object.
str = char(a)
char(a) converts quaternion a to a string of characters.
quaternion::quaternion, quaternion::disp
Display a quaternion object.
disp(a)
disp(a) displays quaternion a. It is also executed implicitly when LME displays the quaternion result of an expression which does not end with a semicolon.
quaternion::quaternion, quaternion::disp, disp
Convert a quaternion object to a matrix of coefficients.
coef = double(a)
double(a) converts quaternion a to a row vector of coefficients for a scalar quaternion, or to an n-by-4 matrix for a vector of quaternions.
q = quaternion(1+2j); double(q) 1 2 0 0