Quaternion Toolbox Overview

Quaternions Biquaternions Octonions Toolbox design principles

Quaternions

Quaternions are four-dimensional hypercomplex numbers (an extension of the complex number concept to higher dimensions). Conventionally, quaternions have four components and can be written in Cartesian form as:

q = w + xi + yj + zk
where the four ‘coefficients’: w, x, y, z are real or complex and the three hypercomplex operators i, j and k are square roots of -1 obeying the following rule: i² = j² = k² = ijk = -1. In what follows, the term ‘quaternion’ means a quaternion with real coefficients w, x, y, z, and the term ‘biquaternion’ is used for the case where the coefficients are complex (strictly if any one of them has a non-zero imaginary part).

Multiplication of quaternions is not commutative, so that, in general, q×p ≠ p×q. Of course, this also applies to biquaternions.

Quaternions have a polar form:

q = |q| exp(μθ)
where
|q|= √(w² + x² + y² + z²)
is the modulus of the quaternion, μ is called the axis (the direction in 3-space of the vector part), and θ is an angle in the range 0 to π.

Biquaternions

The design of the toolbox assumes that the components of a quaternion may be complex. There is no special provision to deal with this. Consequently, the whole toolbox will work for biquaternions. That said, some functions do not yield correct results for biquaternion arrays. Where this is known, the function usually issues a warning if called with a biquaternion argument.

The quaternions are a division algebra, meaning that every non-zero quaternion has a multiplicative inverse. This is not true for the biquaternions, where divisors of zero exist (these have no multiplicative inverse, and zero norm, despite a non-zero value). There are also idempotents in the biquaternions (values that square to give themselves).

Octonions

From version 2 of the toolbox, support is provided for computation with octonion arrays. This is achieved by making maximum use of existing quaternion functions to do as much computation as possible. The internal representation of an octonion is a pair of quaternions (the Cayley-Dickson form). Octonion functionality is very limited because it is not known how to compute many octonion functions yet, or there has not been time to write the missing functions. As with quaternions, the components of an octonion may be complex, but very little is known about complexified octonions, so users who work with them will be entering uncharted territory. There are certainly divisors of zero, so beware.

Symbolic computation

From version 3 of the toolbox, support is provided for computation with quaternions which have symbolic expressions as components. This was extended to octonions with version 3.1. The symbolic functions require the Matlab® Symbolic Toolbox. If this is not present, the symbolic functionality will not work (but there should be no impact on the numeric functionality).

To construct a quaternion with symbolic components you can combine symbolic variables with the quaternion operators represented by the functions qi etc., or you can use the constructor with existing symbolic variables, or you can pass to the constructor the names of symbolic variables represented as character arrays (these must not already exist as the constructor will attempt to create them as symbolic variables).

There is no support for handling quaternions as atomic symbolic quantities (this would require a new class). That is, you cannot create a quaternion which is itself symbolic. The symbolic capability is based on making the three or four components of a quaternion symbolic, and working with three or four symbolic expressions according to the rules of quaternion algebra. Notice carefully that by default symbolic expressions in Matlab® are regarded as complex. If you want to work with real components you need to use the assume function - if applied to a quaternion, this puts an assumption on each of the components. You cannot mix symbolic and numeric components in the same quaternion. If you need a component with a numeric value, declare it as symbolic with the sym function, like this: q = sym(1/2) + sym(1/2) .* mu.

Toolbox design principles

Quaternions are represented by the toolbox in the Cartesian form with four components named w, x, y and z. These components are accessible using the functions s (for scalar), and x, y, z, and also using dotted notation such as q.x for the x component. Quaternion matrices are constructed by the constructor function quaternion which can combine together numeric or symbolic values, variables or matrices to make a full or pure quaternion. Numeric values can be of any numeric type, and the cast function can be used to convert quaternions with one component type to another type, including symbolic ('sym'). To some extent it is also possible to handle quaternions with logical components. It is also possible to make a quaternion value by using the three quaternion ‘operators’, which are provided as parameterless functions qi, qj, qk:

3 .* qi + 4 .* qj
will yield the quaternion value 3i + 4j.

The toolbox has been designed to extend Matlab® in as natural a way as possible. Therefore the user should assume unless there is a reason to do otherwise that the way to carry out an operation is the same as in Matlab®. Where this is not the case, an error should occur. The documentation or the source code for the appropriate function should be consulted to see whether there is a known limitation.

For example, standard Matlab® notation has been overloaded for quaternion arrays, so that the following makes sense to the toolbox if the variables exist as quaternion arrays:

[p q r] * [a b c].'

Even if one of the vectors is replaced by a numeric vector, the result is still computable, since the toolbox can multiply numeric values by quaternions:

>> [1 2 3] * [qi qj qk].'
 
ans = 1 * I + 2 * J + 3 * K

Further, we can replace one element in the left vector by a quaternion, since the toolbox allows quaternion and numeric (non-quaternion) arrays to be concatenated: the numeric array is automatically converted to a quaternion array by putting the numeric values into the scalar part of an otherwise zero quaternion:

>> [1 qj 3] * [qi qj qk].'

ans =
 
     -1 + 1 * I + 0 * J + 3 * K

In most cases where quaternion matrices and vectors are handled it is not necessary to resort to ‘tricks’ to make things work: try the obvious first and if errors occur, work around them by explicit coding, but do not code some clever workaround for a problem that the toolbox can handle for you.

© 2008-2022 Stephen J. Sangwine and Nicolas Le Bihan.

License terms.