Quaternion constructor
q = quaternion(w, x, y, z)
This function constructs quaternion (arrays) from numeric, logical or symbolic components, or character arrays which are the names intended for symbolic components. The latter two cases will work only if the Symbolic Math Toolbox is installed. It accepts from zero to four arguments of the same size, type (numeric, logical, symbolic, character) and class (e.g. double, uint8). The permissible cases are set out in the following paragraphs.
Given no arguments, this function constructs an empty quaternion of class double.
Given one argument which is already a quaternion, the function returns the argument unchanged. If the argument is not a quaternion, the function constructs a quaternion with the argument in the scalar part and supplies a zero vector part of the same type and class as the given argument.
If two arguments are supplied, the first must be numeric, logical or symbolic, and the second must be a pure quaternion of the same size with components of the same type and class as the first argument. The result will be a full quaternion.
If three arguments are supplied, they must be of the same size, type and class. The result will be a pure quaternion.
If four arguments are supplied, they must be of the same size, type and class. The result is a full quaternion.
>> quaternion() ans = [] quaternion >> quaternion(randn('single'), randv('single')) ans = 0.7677 + 0.06019 * I + 0.8961 * J - 0.4397 * K >> class(x(ans)) ans = single >> quaternion(1, 2, 3) ans = 1 * I + 2 * J + 3 * K >> quaternion(1, 2, 3, 4) ans = 1 + 2 * I + 3 * J + 4 * K >> quaternion(randn(2)) ans = 2x2 quaternion array >> syms a b c >> quaternion(a, b, c) ans = a * I + b * J + c * K >> abs(ans) ans = (a^2 + b^2 + c^2)^(1/2)