# quatmultiply

Calculate product of two quaternions

## Description

example

quatprod = quatmultiply(q,r) calculates the quaternion product, quatprod, for two quaternions, q and r.

Aerospace Toolbox uses quaternions that are defined using the scalar-first convention.

Note

Quaternion multiplication is not commutative.

## Examples

collapse all

This example shows how to determine the product of two 1-by-4 quaternions.

q = [1 0 1 0];
r = [1 0.5 0.5 0.75];
mult = quatmultiply(q, r)
mult = 1×4

0.5000    1.2500    1.5000    0.2500

This example shows how to determine the product of a 1-by-4 quaternion with itself.

q = [1 0 1 0];
mult = quatmultiply(q)
mult = 1×4

0     0     2     0

This example shows how to determine the product of 1-by-4 with two 1-by-4 quaternions.

q = [1 0 1 0];
r = [1 0.5 0.5 0.75; 2 1 0.1 0.1];
mult = quatmultiply(q, r)
mult = 2×4

0.5000    1.2500    1.5000    0.2500
1.9000    1.1000    2.1000   -0.9000

## Input Arguments

collapse all

First quaternion or set of quaternions, specified as an m-by-4 matrix or 1-by-4 quaternion. Each element must be real.

q must have its scalar number as the first column.

Data Types: double | single

Second quaternion or set of quaternions, specified as an m-by-4 matrix or 1-by-4 quaternion. Each element must be real.

r must have its scalar number as the first column.

Data Types: double | single

## Output Arguments

collapse all

Output quaternion product, returned as a m-by-4 matrix.

collapse all

### q and r

Input quaternions q and r have the form:

$q={q}_{0}+i{q}_{1}+j{q}_{2}+k{q}_{3}$

and

$r={r}_{0}+i{r}_{1}+j{r}_{2}+k{r}_{3}$

### quatprod

Output quaternion product quatprod has the form of

$n=q×r={n}_{0}+i{n}_{1}+j{n}_{2}+k{n}_{3}$

where

$\begin{array}{l}{n}_{0}=\left({r}_{0}{q}_{0}-{r}_{1}{q}_{1}-{r}_{2}{q}_{2}-{r}_{3}{q}_{3}\right)\\ {n}_{1}=\left({r}_{0}{q}_{1}+{r}_{1}{q}_{0}-{r}_{2}{q}_{3}+{r}_{3}{q}_{2}\right)\\ {n}_{2}=\left({r}_{0}{q}_{2}+{r}_{1}{q}_{3}+{r}_{2}{q}_{0}-{r}_{3}{q}_{1}\right)\\ {n}_{3}=\left({r}_{0}{q}_{3}-{r}_{1}{q}_{2}+{r}_{2}{q}_{1}+{r}_{3}{q}_{0}\right)\end{array}$

## References

[1] Stevens, Brian L., Frank L. Lewis. Aircraft Control and Simulation, 2nd Edition. Hoboken, NJ: John Wiley & Sons, 2003.

## Version History

Introduced in R2006b