Library - quaternion

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 i, j, and k. A quaternion can be written w+ix+jy+kz. The following relationships hold:

i^2 = j^2 = k^2 = ijk = -1

It follows that the product of two quaternions is not commutative.

The following statement makes available functions defined in quaternion:

use quaternion

quaternion::quaternion

Polynom object constructor.

Syntax

a = quaternion
a = quaternion(x)
a = quaternion(z)
a = quaternion(w, x, y, z)

Description

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.

+plusaddition
-minussubtraction
*mtimesproduct
/mrdivideright division
\mldivideleft division
-uminusnegative
+uplusunary plus (no operation)
()subsrefindexing
normquaternion norm (sum of squares)
absabsolute value
conjquaternion conjugate
signnormalization
invinverse

Examples

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

See also

quaternion::disp

quaternion::char

Display a quaternion object.

Syntax

str = char(a)

Description

char(a) converts quaternion a to a string of characters.

See also

quaternion::quaternion, quaternion::disp

quaternion::disp

Display a quaternion object.

Syntax

disp(a)

Description

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.

See also

quaternion::quaternion, quaternion::disp, disp

quaternion::double

Convert a quaternion object to a matrix of coefficients.

Syntax

coef = double(a)

Description

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.

Example

q = quaternion(1+2j);
double(q)
  1 2 0 0

See also

quaternion::quaternion


Copyright 2001, Calerga.

All rights reserved.