# mtimes, *

Quaternion multiplication

## Syntax

``quatC = A*B``

## Description

example

````quatC = A*B` implements quaternion multiplication if either `A` or `B` is a quaternion. Either `A` or `B` must be a scalar.You can use quaternion multiplication to compose rotation operators: To compose a sequence of frame rotations, multiply the quaternions in the order of 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 ${\left(pq\right)}^{\ast }v\left(pq\right)$, where v represents the object to rotate specified 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 $\left(qp\right)v{\left(qp\right)}^{\ast }$. ```

## Examples

collapse all

Create a 4-by-1 column vector, `A`, and a scalar, `b`. Multiply `A` times `b`.

`A = quaternion(randn(4,4))`
```A = 4x1 quaternion array 0.53767 + 0.31877i + 3.5784j + 0.7254k 1.8339 - 1.3077i + 2.7694j - 0.063055k -2.2588 - 0.43359i - 1.3499j + 0.71474k 0.86217 + 0.34262i + 3.0349j - 0.20497k ```
`b = quaternion(randn(1,4))`
```b = quaternion -0.12414 + 1.4897i + 1.409j + 1.4172k ```
`C = A*b`
```C = 4x1 quaternion array -6.6117 + 4.8105i + 0.94224j - 4.2097k -2.0925 + 6.9079i + 3.9995j - 3.3614k 1.8155 - 6.2313i - 1.336j - 1.89k -4.6033 + 5.8317i + 0.047161j - 2.791k ```

## Input Arguments

collapse all

Input to multiply, specified as a quaternion, array of quaternions, real scalar, or array of real scalars.

If `B` is nonscalar, then `A` must be scalar.

Data Types: `quaternion` | `single` | `double`

Input to multiply, specified as a quaternion, array of quaternions, real scalar, or array of real scalars.

If `A` is nonscalar, then `B` must be scalar.

Data Types: `quaternion` | `single` | `double`

## Output Arguments

collapse all

Quaternion product, returned as a quaternion or array of quaternions.

Data Types: `quaternion`

## Algorithms

collapse all

### Quaternion Multiplication by a Real Scalar

Given a quaternion

`$q={a}_{\text{q}}+{b}_{\text{q}}\text{i}+{c}_{\text{q}}\text{j}+{d}_{\text{q}}\text{k,}$`

the product of q and a real scalar β is

`$\beta q=\beta {a}_{\text{q}}+\beta {b}_{\text{q}}\text{i}+\beta {c}_{\text{q}}\text{j}+\beta {d}_{\text{q}}\text{k}$`

### Quaternion Multiplication by a Quaternion Scalar

The definition of the basis elements for quaternions,

`${\text{i}}^{2}={\text{j}}^{2}={\text{k}}^{2}=\text{ijk}=-1\text{\hspace{0.17em}},$`

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}_{\text{q}}+{b}_{\text{q}}\text{i}+{c}_{\text{q}}\text{j}+{d}_{\text{q}}\text{k,}$ and $p={a}_{\text{p}}+{b}_{\text{p}}\text{i}+{c}_{\text{p}}\text{j}+{d}_{\text{p}}\text{k}$, the multiplication can be expanded as:

`$\begin{array}{l}z=pq=\left({a}_{\text{p}}+{b}_{\text{p}}\text{i}+{c}_{\text{p}}\text{j}+{d}_{\text{p}}\text{k}\right)\left({a}_{\text{q}}+{b}_{\text{q}}\text{i}+{c}_{\text{q}}\text{j}+{d}_{\text{q}}\text{k}\right)\\ \text{ }\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}={a}_{\text{p}}{a}_{\text{q}}+{a}_{\text{p}}{b}_{\text{q}}\text{i}+{a}_{\text{p}}{c}_{\text{q}}\text{j}+{a}_{\text{p}}{d}_{\text{q}}\text{k}\\ \text{ }\text{ }+{b}_{\text{p}}{a}_{\text{q}}\text{i}+{b}_{\text{p}}{b}_{\text{q}}{\text{i}}^{2}+{b}_{\text{p}}{c}_{\text{q}}\text{ij}+{b}_{\text{p}}{d}_{\text{q}}\text{ik}\\ \text{ }\text{ }+{c}_{\text{p}}{a}_{\text{q}}\text{j}+{c}_{\text{p}}{b}_{\text{q}}\text{ji}+{c}_{\text{p}}{c}_{\text{q}}{\text{j}}^{2}+{c}_{\text{p}}{d}_{\text{q}}\text{jk}\\ \text{ }\text{ }+{d}_{\text{p}}{a}_{\text{q}}k+{d}_{\text{p}}{b}_{\text{q}}\text{ki}+{d}_{\text{p}}{c}_{\text{q}}\text{kj}+{d}_{\text{p}}{d}_{\text{q}}{\text{k}}^{2}\end{array}$`

You can simplify the equation using the quaternion multiplication table:

`$\begin{array}{l}z=pq\text{\hspace{0.17em}}={a}_{\text{p}}{a}_{\text{q}}+{a}_{\text{p}}{b}_{\text{q}}\text{i}+{a}_{\text{p}}{c}_{\text{q}}\text{j}+{a}_{\text{p}}{d}_{\text{q}}\text{k}\\ \text{ }\text{ }+{b}_{\text{p}}{a}_{\text{q}}\text{i}-{b}_{\text{p}}{b}_{\text{q}}+{b}_{\text{p}}{c}_{\text{q}}\text{k}-{b}_{\text{p}}{d}_{\text{q}}\text{j}\\ \text{ }\text{ }+{c}_{\text{p}}{a}_{\text{q}}\text{j}-{c}_{\text{p}}{b}_{\text{q}}\text{k}-{c}_{\text{p}}{c}_{\text{q}}+{c}_{\text{p}}{d}_{\text{q}}\text{i}\\ \text{ }\text{ }+{d}_{\text{p}}{a}_{\text{q}}k+{d}_{\text{p}}{b}_{\text{q}}\text{j}-{d}_{\text{p}}{c}_{\text{q}}\text{i}-{d}_{\text{p}}{d}_{\text{q}}\end{array}$`

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

## Version History

Introduced in R2019b