Main Content

times,.*

Element-wise quaternion multiplication

Since R2018b

Syntax

Description

example

quatC=A.*Breturns 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 apquaternion followed by aqquaternion, multiply in the order魁人党. The rotation operator becomes ( p q ) v ( p q ) , wherevrepresents 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 apquaternion followed by aqquaternion, multiply in the reverse order,qp. The rotation operator becomes ( q p ) v ( q p ) .

Examples

collapse all

Create two vectors,AandB, 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,AandB, 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 array0.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 =logical0

Create a row vectoraand a column vectorb, 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 array0 + 0i + 0j + 0k 1 + 0i + 0j + 0k 0.53767 + 1.8339i - 2.2588j + 0.86217k
b = quaternion(randn(4,4))
b =4x1 quaternion array0.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 array0 + 0 + 0 j + 0 k 0.31877 + 3.5784 + 0.7254 j - 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

Array to multiply, specified as a quaternion, an array of quaternions, a real scalar, or an array of real numbers.

AandBmust 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.

Data Types:quaternion|single|double

Array to multiply, specified as a quaternion, an array of quaternions, a real scalar, or an array of real numbers.

AandBmust 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.

Data Types:quaternion|single|double

Output Arguments

collapse all

Quaternion product, returned as a scalar, vector, matrix, or multidimensional array.

Data Types:quaternion

Algorithms

collapse all

Quaternion Multiplication by a Real Scalar

Given a quaternion,

q = a q + b q i + c q j + d q k,

the product ofqand a real scalarβis

β q = β a q + β b q i + β c q j + β d q k

Quaternion Multiplication by a Quaternion Scalar

The definition of the basis elements for quaternions,

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

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

1 i j k
1 1 i j k
i i −1 k −j
j j −k −1 i
k k j −i −1

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

Given two quaternions, q = a q + b q i + c q j + d q k, and p = a p + b p i + c p j + d p k , the multiplication can be expanded as:

z = p q = ( a p + b p i + c p j + d p k ) ( a q + b q i + c q j + d q k ) = a p a q + a p b q i + a p c q j + a p d q k + b p a q i + b p b q i 2 + b p c q ij + b p d q ik + c p a q j + c p b q ji + c p c q j 2 + c p d q jk + d p a q k + d p b q ki + d p c q kj + d p d q k 2

你可以简化equation using the quaternion multiplication table.

z = p q = a p a q + a p b q i + a p c q j + a p d q k + b p a q i b p b q + b p c q k b p d q j + c p a q j c p b q k c p c q + c p d q i + d p a q k + d p b q j d p c q i d p d q

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 R2018b