Main Content

times, .*

Element-wise quaternion multiplication

Since R2020b

Description

quatC = A.*B returns the element-by-element quaternion multiplication of quaternion arrays.

You can use quaternion multiplication to compose rotation operators:

  • To compose a sequence of frame rotations, multiply the quaternions in the same order as the desired sequence of rotations. For example, to apply a p quaternion followed by a q quaternion, multiply in the order pq. The rotation operator becomes (pq)v(pq), where v represents the object to rotate in quaternion form. * represents conjugation.

  • To compose a sequence of point rotations, multiply the quaternions in the reverse order of the desired sequence of rotations. For example, to apply a p quaternion followed by a q quaternion, multiply in the reverse order, qp. The rotation operator becomes (qp)v(qp).

example

Examples

collapse all

Create two vectors, A and B, and multiply them element by element.

A = quaternion([1:4;5:8]);
B = A;
C = A.*B
C = 2x1 quaternion array
     -28 +   4i +   6j +   8k
    -124 +  60i +  70j +  80k

Create two 3-by-3 arrays, A and B, and multiply them element by element.

A = reshape(quaternion(randn(9,4)),3,3);
B = reshape(quaternion(randn(9,4)),3,3);
C = A.*B
C = 3x3 quaternion array
     0.60169 +  2.4332i -  2.5844j + 0.51646k    -0.49513 +  1.1722i +  4.4401j -   1.217k      2.3126 + 0.16856i +  1.0474j -  1.0921k
     -4.2329 +  2.4547i +  3.7768j + 0.77484k    -0.65232 - 0.43112i -  1.4645j - 0.90073k     -1.8897 - 0.99593i +  3.8331j + 0.12013k
     -4.4159 +  2.1926i +  1.9037j -  4.0303k     -2.0232 +  0.4205i - 0.17288j +  3.8529k     -2.9137 -  5.5239i -  1.3676j +  3.0654k

Note that quaternion multiplication is not commutative:

isequal(C,B.*A)
ans = logical
   0

Create a row vector a and a column vector b, then multiply them. The 1-by-3 row vector and 4-by-1 column vector combine to produce a 4-by-3 matrix with all combinations of elements multiplied.

a = [zeros("quaternion"),ones("quaternion"),quaternion(randn(1,4))]
a = 1x3 quaternion array
           0 +       0i +       0j +       0k           1 +       0i +       0j +       0k     0.53767 +  1.8339i -  2.2588j + 0.86217k

b = quaternion(randn(4,4))
b = 4x1 quaternion array
      0.31877 +   3.5784i +   0.7254j -  0.12414k
      -1.3077 +   2.7694i - 0.063055j +   1.4897k
     -0.43359 -   1.3499i +  0.71474j +    1.409k
      0.34262 +   3.0349i -  0.20497j +   1.4172k

a.*b
ans = 4x3 quaternion array
            0 +        0i +        0j +        0k      0.31877 +   3.5784i +   0.7254j -  0.12414k      -4.6454 +   2.1636i +   2.9828j +   9.6214k
            0 +        0i +        0j +        0k      -1.3077 +   2.7694i - 0.063055j +   1.4897k      -7.2087 -   4.2197i +   2.5758j +   5.8136k
            0 +        0i +        0j +        0k     -0.43359 -   1.3499i +  0.71474j +    1.409k       2.6421 -     5.32i -   2.3841j -   1.3547k
            0 +        0i +        0j +        0k      0.34262 +   3.0349i -  0.20497j +   1.4172k      -7.0663 -  0.76439i -  0.86648j +   7.5369k

Input Arguments

collapse all

Input to multiply, specified as a quaternion object, an array of quaternion objects of any dimensionality, a real scalar, or an array of real numbers of any dimensionality. Numeric values must be of data type single or double.

A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same or one of them is 1.

Input to multiply, specified as a quaternion object, an array of quaternion objects of any dimensionality, a real scalar, or an array of real numbers of any dimensionality. Numeric values must be of data type single or double.

A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same or one of them is 1.

Output Arguments

collapse all

Quaternion product, returned as a quaternion object or an array of quaternion objects.

Algorithms

collapse all

Quaternion Multiplication by a Real Scalar

Given a quaternion,

q=aq+bqi+cqj+dqk,

the product of q and a real scalar β is

βq=βaq+βbqi+βcqj+βdqk

Quaternion Multiplication by a Quaternion Scalar

The definition of the basis elements for quaternions,

i2=j2=k2=ijk=-1,

can be expanded to populate a table summarizing quaternion basis element multiplication:

 1ijk
11ijk
ii−1k−j
jj−k−1i
kkj−i−1

When reading the table, the rows are read first, for example: ij = k and ji = −k.

Given two quaternions, q=aq+bqi+cqj+dqk, and p=ap+bpi+cpj+dpk, the multiplication can be expanded as:

z=pq=(ap+bpi+cpj+dpk)(aq+bqi+cqj+dqk)=apaq+apbqi+apcqj+apdqk+bpaqi+bpbqi2+bpcqij+bpdqik+cpaqj+cpbqji+cpcqj2+cpdqjk+dpaqk+dpbqki+dpcqkj+dpdqk2

You can simplify the equation using the quaternion multiplication table.

z=pq=apaq+apbqi+apcqj+apdqk+bpaqibpbq+bpcqkbpdqj+cpaqjcpbqkcpcq+cpdqi+dpaqk+dpbqjdpcqidpdq

References

[1] Kuipers, Jack B. Quaternions and Rotation Sequences: A Primer with Applications to Orbits, Aerospace, and Virtual Reality. Princeton, NJ: Princeton University Press, 2007.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b

See Also

Functions

Objects