# quatdivide

Divide quaternion by another quaternion

## Syntax

``n = quatdivide(q,r)``

## Description

example

````n = quatdivide(q,r)` calculates the result of quaternion division `n` for two given quaternions, `q` and `r`. For more information on the input and output quaternion forms, see Algorithms.Aerospace Toolbox uses quaternions that are defined using the scalar-first convention.```

## Examples

collapse all

Divide one 1-by-4 quaternions by another 1-by-4 quaternion.

```q = [1 0 1 0]; r = [1 0.5 0.5 0.75]; d = quatdivide(q, r)```
```d = 1×4 0.7273 0.1212 0.2424 -0.6061 ```

Divide a 2-by-4 quaternion by a 1-by-4 quaternion.

```q = [1 0 1 0; 2 1 0.1 0.1]; r = [1 0.5 0.5 0.75]; d = quatdivide(q, r)```
```d = 2×4 0.7273 0.1212 0.2424 -0.6061 1.2727 0.0121 -0.7758 -0.4606 ```

## Input Arguments

collapse all

Numerator quaternion, specified in a m-by-4 matrix of real numbers containing m quaternions or a 1-by-4 matrix of reall numbers containing one quaternion.

Example: `[1 0 1 0]`

Data Types: `double`

Denominator quaternion, specified in a m-by-4 matrix of real numbers containing m quaternions or a 1-by-4 matrix of real numbers containing one quaternion.

Example: `[1 0.5 0.5 0.75]`

Data Types: `double`

## Output Arguments

collapse all

Quaternion quotients, returned in an m-by-4 matrix of real numbers.

## Algorithms

The quaternions have the form of

`$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}.$`

The resulting quaternion from the division has the form of

`$t=\frac{q}{r}={t}_{0}+i{t}_{1}+j{t}_{2}+k{t}_{3}.$`

where

`$\begin{array}{l}{t}_{0}=\frac{\left({r}_{0}{q}_{0}+{r}_{1}{q}_{1}+{r}_{2}{q}_{2}+{r}_{3}{q}_{3}\right)}{{r}_{0}^{2}+{r}_{1}^{2}+{r}_{2}^{2}+{r}_{3}^{2}}\\ {t}_{1}=\frac{\left({r}_{0}{q}_{1}-{r}_{1}{q}_{0}-{r}_{2}{q}_{3}+{r}_{3}{q}_{2}\right)}{{r}_{0}^{2}+{r}_{1}^{2}+{r}_{2}^{2}+{r}_{3}^{2}}\\ {t}_{2}=\frac{\left({r}_{0}{q}_{2}+{r}_{1}{q}_{3}-{r}_{2}{q}_{0}-{r}_{3}{q}_{1}\right)}{{r}_{0}^{2}+{r}_{1}^{2}+{r}_{2}^{2}+{r}_{3}^{2}}\\ {t}_{3}=\frac{\left({r}_{0}{q}_{3}-{r}_{1}{q}_{2}+{r}_{2}{q}_{1}-{r}_{3}{q}_{0}\right)}{{r}_{0}^{2}+{r}_{1}^{2}+{r}_{2}^{2}+{r}_{3}^{2}}.\end{array}$`

 Stevens, Brian L. and Frank L. Lewis. Aircraft Control and Simulation. 2nd ed. Wiley–Interscience, 2003.