Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random | Template Test |  
Login
create new user
Username:
Password:
forget your password?
Main Menu
Sections

Meta

Talkback

Downloads

Information
[parent] quaternion exercises for physics and engineering (Example)

Quaternion exercises for physics and engineering

This article is a consolidated problem set for the PhysicsLibrary quaternion sequence. The problems begin with algebra and conventions, then move through rotation geometry, direction cosine matrices, Euler angles, quaternion kinematics, attitude errors, and IMU propagation.

All problems are stated first. Complete solutions appear afterward so that the article can be used for self study.

Convention declaration

Unless a problem explicitly states otherwise, use the following conventions:

  1. all physical frames are right-handed orthonormal Cartesian frames;
  2. Hamilton multiplication is used,
    $\displaystyle \mathbf i\mathbf j=\mathbf k,\qquad \mathbf j\mathbf k=\mathbf i,\qquad \mathbf k\mathbf i=\mathbf j;$ (1)
  3. quaternions are displayed in scalar-first form,
    $\displaystyle q= \begin{bmatrix} q_w&q_x&q_y&q_z \end{bmatrix}^{T};$ (2)
  4. an active vector rotation is
    $\displaystyle \mathbf v'=q\mathbf v q^*$ (3)
    for unit $q$;
  5. the attitude quaternion
    $\displaystyle q={}^Iq_B$ (4)
    maps body coordinates into inertial coordinates;
  6. body resolved angular velocity satisfies
    $\displaystyle \dot q=\frac12q\omega^B.$ (5)

Problems

Problem 1: quaternion components

Write

$\displaystyle q=3-2\mathbf i+4\mathbf j-\mathbf k$ (6)
as a scalar part and vector part.

Problem 2: basis multiplication

Evaluate

$\displaystyle \mathbf i\mathbf j,\qquad \mathbf j\mathbf i,\qquad \mathbf k\mathbf k.$ (7)

Problem 3: quaternion product

Let

$\displaystyle p=1+2\mathbf i-\mathbf j, \qquad q=2+\mathbf i+3\mathbf k.$ (8)
Compute $pq$.

Problem 4: noncommutativity

Using the same $p$ and $q$ as Problem 3, compute $qp$ and show explicitly that $pq\neq qp$.

Problem 5: scalar vector product form

For

$\displaystyle p=(p_w,\mathbf p), \qquad q=(q_w,\mathbf q),$ (9)
write the quaternion product in scalar vector form.

Problem 6: pure vector product

Let

$\displaystyle \mathbf a= \begin{bmatrix} 1\\ 2\\ 0 \end{bmatrix}, \qquad \mathbf b= \begin{bmatrix} 0\\ 1\\ 3 \end{bmatrix}.$ (10)
Treat them as pure quaternions and compute $\mathbf a\mathbf b$.

Problem 7: conjugate

For

$\displaystyle q=2-3\mathbf i+4\mathbf j+5\mathbf k,$ (11)
compute $q^*$.

Problem 8: norm

For the quaternion in Problem 7, compute $\Vert q\Vert$ and $\Vert q\Vert^2$.

Problem 9: inverse

For the quaternion in Problem 7, compute $q^{-1}$.

Problem 10: unit quaternion check

Determine whether

$\displaystyle q= \begin{bmatrix} \frac12& \frac12& \frac12& \frac12 \end{bmatrix}^{T}$ (12)
is a unit quaternion.

Problem 11: axis angle to quaternion

Find the unit quaternion for a $60^\circ$ active rotation about

$\displaystyle \widehat{\mathbf u} = \frac{1}{\sqrt3} \begin{bmatrix} 1\\ 1\\ 1 \end{bmatrix}.$ (13)

Problem 12: sign ambiguity

Explain why $q$ and $-q$ represent the same physical rotation.

Problem 13: rotate a basis vector

Use

$\displaystyle q=\frac{1+\mathbf k}{\sqrt2}$ (14)
to rotate
$\displaystyle \mathbf v= \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}.$ (15)

Problem 14: vector rotation formula

Write the vector only quaternion rotation formula in terms of $q_w$, $\mathbf q$, and $\mathbf v$.

Problem 15: parallel vector special case

A unit quaternion represents rotation about axis $\widehat{\mathbf u}$. What happens to a vector parallel to $\widehat{\mathbf u}$?

Problem 16: composition order

Quaternion $q_1$ acts first and quaternion $q_2$ acts second. What is the net quaternion?

Problem 17: noncommuting rotations

Apply a $90^\circ$ active rotation about $x$ and then a $90^\circ$ active rotation about $y$ to

$\displaystyle \mathbf v= \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix}.$ (16)
Then reverse the order. Compare the results.

Problem 18: quaternion to direction cosine matrix

Find $R(q)$ for

$\displaystyle q=\frac{1+\mathbf k}{\sqrt2}.$ (17)

Problem 19: matrix columns

What is the geometric meaning of the columns of an active rotation matrix $R(q)$?

Problem 20: transpose and conjugate

For a unit quaternion, show the relation among

$\displaystyle R(q^*),\qquad R(q)^{-1},\qquad R(q)^T.$ (18)

Problem 21: matrix to quaternion

Recover one quaternion corresponding to

$\displaystyle R= \begin{bmatrix} 0&-1&0\ 1&0&0\ 0&0&1 \end{bmatrix}.$ (19)

Problem 22: matrix recovery near $180^\circ$

For

$\displaystyle R= \begin{bmatrix} 1&0&0\ 0&-1&0\ 0&0&-1 \end{bmatrix},$ (20)
find a corresponding quaternion and explain why a trace formula based on division by $q_w$ is poor here.

Problem 23: Euler angles to quaternion

For the 3 2 1 yaw pitch roll convention

$\displaystyle R=R_z(\psi)R_y(\theta)R_x(\phi),$ (21)
find the quaternion for
$\displaystyle \phi=0,\qquad \theta=0,\qquad \psi=90^\circ.$ (22)

Problem 24: pure roll

Find the quaternion corresponding to

$\displaystyle \phi=90^\circ,\qquad \theta=0,\qquad \psi=0.$ (23)

Problem 25: gimbal lock

For the 3 2 1 sequence, at what pitch angles does the Euler angle representation become singular, and what geometric alignment occurs?

Problem 26: body resolved quaternion kinematics

State the quaternion differential equation for $q={}^Iq_B$ when angular velocity is resolved in body coordinates.

Problem 27: inertial resolved quaternion kinematics

State the corresponding equation when angular velocity is resolved in inertial coordinates.

Problem 28: constant rate propagation

A body starts at

$\displaystyle q(0)=1$ (24)
and rotates at a constant body rate
$\displaystyle \boldsymbol\omega^B= \begin{bmatrix} 0\\ 0\\ \Omega \end{bmatrix}.$ (25)
Find $q(t)$.

Problem 29: exact IMU increment

An IMU reports a bias corrected body rate of

$\displaystyle \boldsymbol\omega^B= \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix}$ rad/s (26)
for
$\displaystyle \Delta t=0.01$ s$\displaystyle .$ (27)
Find the exact incremental quaternion.

Problem 30: small angle IMU increment

For Problem 29, compute the first order small angle incremental quaternion.

Problem 31: gyro bias drift

An uncorrected gyro bias is

$\displaystyle 0.05^\circ/$s$\displaystyle .$ (28)
Estimate the resulting attitude error after five minutes.

Problem 32: forward Euler norm drift

Write one forward Euler quaternion update and explain why normalization is commonly applied afterward.

Problem 33: relative attitude

Let $q$ be the actual attitude and $q_d$ the desired attitude. Write the inertial side error quaternion $\delta q_I$ such that

$\displaystyle q_d=\delta q_I q.$ (29)

Problem 34: body side error

Write the body side error quaternion $\delta q_B$ such that

$\displaystyle q_d=q\delta q_B.$ (30)

Problem 35: small attitude error

For a small attitude error, relate the vector part of $\delta q$ to the three component error vector $\delta\boldsymbol\theta$.

Problem 36: sign choice for an error quaternion

Why is it often useful to choose the equivalent error quaternion with

$\displaystyle \delta q_w\geq0?$ (31)

Problem 37: coning cross term

For two small body delta angles applied in chronological order, write the leading approximation for the equivalent rotation vector.

Problem 38: numerical coning example

Let

$\displaystyle \Delta\boldsymbol\theta_1= \begin{bmatrix} 0.02\\ 0\\ 0 \end{bmat... ..., \qquad \Delta\boldsymbol\theta_2= \begin{bmatrix} 0\\ 0.03\\ 0 \end{bmatrix}.$ (32)
Compute the leading cross term
$\displaystyle \frac12 \Delta\boldsymbol\theta_1 \times \Delta\boldsymbol\theta_2.$ (33)

Problem 39: IMU navigation flow

Describe the order in which gyro data, quaternion attitude, accelerometer specific force, and velocity are used in a basic strapdown navigation propagation.

Problem 40: comprehensive attitude update

A vehicle has current attitude

$\displaystyle q_k= \begin{bmatrix} 1&0&0&0 \end{bmatrix}^{T}.$ (34)
The gyro measurement is
$\displaystyle \boldsymbol\omega_m^B= \begin{bmatrix} 0.10\\ 0.20\\ 0.30 \end{bmatrix}$ rad/s$\displaystyle ,$ (35)
the estimated gyro bias is
$\displaystyle \widehat{\mathbf b}_g= \begin{bmatrix} 0.01\\ 0.02\\ 0.03 \end{bmatrix}$ rad/s$\displaystyle ,$ (36)
and
$\displaystyle \Delta t=0.02$ s$\displaystyle .$ (37)
Compute the corrected rate, delta angle, and a first order propagated quaternion.

Solutions

Solution 1

The scalar part is

$\displaystyle q_w=3,$ (38)
and the vector part is
$\displaystyle \mathbf q= \begin{bmatrix} -2\\ 4\\ -1 \end{bmatrix}.$ (39)

Solution 2

Hamilton multiplication gives

$\displaystyle \mathbf i\mathbf j=\mathbf k, \qquad \mathbf j\mathbf i=-\mathbf k, \qquad \mathbf k\mathbf k=-1.$ (40)

Solution 3

Write

$\displaystyle p=(1,[2,-1,0]^T), \qquad q=(2,[1,0,3]^T).$ (41)
The scalar part is
$\displaystyle 1(2)-[2,-1,0] \begin{bmatrix} 1\\ 0\\ 3 \end{bmatrix}=2-2=0.$ (42)
The vector part is
$\displaystyle 1 \begin{bmatrix} 1\\ 0\\ 3 \end{bmatrix}+ 2 \begin{bmatrix} 2\\ ... ...gin{bmatrix} 1\\ 0\\ 3 \end{bmatrix}= \begin{bmatrix} 2\\ -8\\ 4 \end{bmatrix}.$ (43)
Therefore
$\displaystyle \boxed{ pq=2\mathbf i-8\mathbf j+4\mathbf k. }$ (44)

Solution 4

The scalar part is again zero. The vector part is

$\displaystyle 2 \begin{bmatrix} 2\\ -1\\ 0 \end{bmatrix}+ 1 \begin{bmatrix} 1\\... ...gin{bmatrix} 2\\ -1\\ 0 \end{bmatrix}= \begin{bmatrix} 8\\ 4\\ 2 \end{bmatrix}.$ (45)
Thus
$\displaystyle \boxed{ qp=8\mathbf i+4\mathbf j+2\mathbf k, }$ (46)
which differs from $pq$.

Solution 5

The scalar vector product is

$\displaystyle \boxed{ (p_w,\mathbf p)(q_w,\mathbf q) = \left( p_wq_w-\mathbf p\cdot\mathbf q,\, p_w\mathbf q+q_w\mathbf p+\mathbf p\times\mathbf q \right). }$ (47)

Solution 6

For pure vectors,

$\displaystyle \mathbf a\mathbf b = -\mathbf a\cdot\mathbf b + \mathbf a\times\mathbf b.$ (48)
The dot product is
$\displaystyle \mathbf a\cdot\mathbf b=2.$ (49)
The cross product is
$\displaystyle \mathbf a\times\mathbf b= \begin{bmatrix} 6\\ -3\\ 1 \end{bmatrix}.$ (50)
Therefore
$\displaystyle \boxed{ \mathbf a\mathbf b = -2+6\mathbf i-3\mathbf j+\mathbf k. }$ (51)

Solution 7

The conjugate reverses the vector part:

$\displaystyle \boxed{ q^*=2+3\mathbf i-4\mathbf j-5\mathbf k. }$ (52)

Solution 8

The squared norm is

$\displaystyle \Vert q\Vert^2 = 2^2+(-3)^2+4^2+5^2 = 54.$ (53)
Hence
$\displaystyle \boxed{ \Vert q\Vert=3\sqrt6. }$ (54)

Solution 9

Using

$\displaystyle q^{-1}=\frac{q^*}{\Vert q\Vert^2},$ (55)
we obtain
$\displaystyle \boxed{ q^{-1} = \frac{1}{54} \left( 2+3\mathbf i-4\mathbf j-5\mathbf k \right). }$ (56)

Solution 10

The squared norm is

$\displaystyle \Vert q\Vert^2 = 4\left(\frac12\right)^2 = 1.$ (57)
Therefore it is a unit quaternion.

Solution 11

For angle $\theta=60^\circ$,

$\displaystyle q = \cos\frac{\theta}{2} + \widehat{\mathbf u} \sin\frac{\theta}{2}.$ (58)
Thus
$\displaystyle \boxed{ q= \frac{\sqrt3}{2} + \frac{1}{2\sqrt3} \left( \mathbf i+\mathbf j+\mathbf k \right). }$ (59)

Solution 12

The rotated vector is

$\displaystyle \mathbf v'=q\mathbf v q^*.$ (60)
Replacing $q$ by $-q$ gives
$\displaystyle (-q)\mathbf v(-q)^* = (-q)\mathbf v(-q^*) = q\mathbf v q^*.$ (61)
Therefore the physical rotation is unchanged.

Solution 13

The quaternion is a $90^\circ$ active rotation about $z$. Therefore

$\displaystyle \boxed{ \mathbf v'= \begin{bmatrix} 0\\ 1\\ 0 \end{bmatrix}. }$ (62)

Solution 14

The vector only formula is

$\displaystyle \boxed{ \mathbf v' = \mathbf v + 2q_w(\mathbf q\times\mathbf v) + 2\mathbf q\times(\mathbf q\times\mathbf v). }$ (63)

Solution 15

A vector parallel to the rotation axis is unchanged:

$\displaystyle \boxed{ \mathbf v'=\mathbf v. }$ (64)

Solution 16

If $q_1$ acts first and $q_2$ acts second, then

$\displaystyle \boxed{ q_{\mathrm{net}}=q_2q_1. }$ (65)

Solution 17

Starting from $\mathbf e_3$, a $90^\circ$ rotation about $x$ gives

$\displaystyle \mathbf e_3\mapsto-\mathbf e_2.$ (66)
A subsequent $90^\circ$ rotation about $y$ leaves $-\mathbf e_2$ unchanged, so
$\displaystyle \boxed{ \mathbf v_{\mathrm{xy}}=-\mathbf e_2. }$ (67)
Reversing the order,
$\displaystyle \mathbf e_3\mapsto\mathbf e_1$ (68)
under the $y$ rotation, and the later $x$ rotation leaves $\mathbf e_1$ unchanged. Therefore
$\displaystyle \boxed{ \mathbf v_{\mathrm{yx}}=\mathbf e_1. }$ (69)
The different answers demonstrate noncommutativity.

Solution 18

The matrix is

$\displaystyle \boxed{ R(q)= \begin{bmatrix} 0&-1&0\ 1&0&0\ 0&0&1 \end{bmatrix}. }$ (70)

Solution 19

The columns are the images of the basis vectors:

$\displaystyle R(q) = \begin{bmatrix} R(q)\mathbf e_1& R(q)\mathbf e_2& R(q)\mathbf e_3 \end{bmatrix}.$ (71)

Solution 20

For a unit quaternion,

$\displaystyle \boxed{ R(q^*)=R(q)^{-1}=R(q)^T. }$ (72)

Solution 21

The matrix is a $90^\circ$ active rotation about $z$, so one choice is

$\displaystyle \boxed{ q=\frac{1+\mathbf k}{\sqrt2}. }$ (73)
Its negative is equally valid.

Solution 22

The matrix is a $180^\circ$ active rotation about $x$, so

$\displaystyle \boxed{ q=\mathbf i }$ (74)
or $-\mathbf i$ is valid. Here
$\displaystyle q_w=0.$ (75)
Therefore a recovery formula that divides by $q_w$ is singular or numerically fragile. A largest component branch should be used instead.

Solution 23

This is pure $90^\circ$ yaw, so

$\displaystyle \boxed{ q= \frac{1+\mathbf k}{\sqrt2}. }$ (76)

Solution 24

This is pure $90^\circ$ roll, so

$\displaystyle \boxed{ q= \frac{1+\mathbf i}{\sqrt2}. }$ (77)

Solution 25

The 3 2 1 representation becomes singular at

$\displaystyle \boxed{ \theta=\pm90^\circ. }$ (78)
At these attitudes the yaw and roll axes align, so the coordinate representation loses one independent direction.

Solution 26

For body resolved angular velocity,

$\displaystyle \boxed{ \dot q=\frac12q\omega^B. }$ (79)

Solution 27

For inertial resolved angular velocity,

$\displaystyle \boxed{ \dot q=\frac12\omega^I q. }$ (80)

Solution 28

The rotation is about the $z$ axis through angle $\Omega t$, so

$\displaystyle \boxed{ q(t) = \cos\frac{\Omega t}{2} + \mathbf k\sin\frac{\Omega t}{2}. }$ (81)

Solution 29

The delta angle is

$\displaystyle \Delta\boldsymbol\theta= \begin{bmatrix} 0\\ 0\\ 0.01 \end{bmatrix}$ rad$\displaystyle .$ (82)
Thus
$\displaystyle \boxed{ \delta q= \begin{bmatrix} \cos0.005\ 0\ 0\ \sin0.00... ...trix}\approx \begin{bmatrix} 0.9999875\ 0\ 0\ 0.00499998 \end{bmatrix}. }$ (83)

Solution 30

The first order small angle increment is

$\displaystyle \boxed{ \delta q \approx \begin{bmatrix} 1\ 0\ 0\ 0.005 \end{bmatrix}. }$ (84)

Solution 31

Five minutes is 300 s. The approximate error is

$\displaystyle \delta\theta \approx 0.05^\circ/$s$\displaystyle \times300$ s$\displaystyle = 15^\circ.$ (85)

Solution 32

Forward Euler gives

$\displaystyle q_{k+1}^{\mathrm E} = q_k+\frac12q_k\omega_k^B\Delta t.$ (86)
This step is only tangent to the unit quaternion sphere to first order, so
$\displaystyle \left\Vert q_{k+1}^{\mathrm E}\right\Vert \neq1$ (87)
in general. A common correction is
$\displaystyle \boxed{ q_{k+1} = \frac{q_{k+1}^{\mathrm E}} {\left\Vert q_{k+1}^{\mathrm E}\right\Vert}. }$ (88)

Solution 33

From

$\displaystyle q_d=\delta q_Iq,$ (89)
right multiply by $q^*$:
$\displaystyle \boxed{ \delta q_I=q_dq^*. }$ (90)

Solution 34

From

$\displaystyle q_d=q\delta q_B,$ (91)
left multiply by $q^*$:
$\displaystyle \boxed{ \delta q_B=q^*q_d. }$ (92)

Solution 35

For a small error,

$\displaystyle \delta q \approx \begin{bmatrix} 1\\ [1mm] \dfrac12\delta\boldsymbol\theta \end{bmatrix}.$ (93)
Therefore
$\displaystyle \boxed{ \delta\boldsymbol\theta \approx 2\,\delta\mathbf q_v. }$ (94)

Solution 36

The quaternions $\delta q$ and $-\delta q$ represent the same relative rotation. Choosing

$\displaystyle \delta q_w\geq0$ (95)
selects the representative associated with the principal rotation angle from 0 to $\pi$. This is usually the smaller attitude correction.

Solution 37

For two small body increments,

$\displaystyle \boxed{ \Delta\boldsymbol\theta_{\mathrm{eq}} \approx \Delta\bold... ...\theta_2+ \frac12 \Delta\boldsymbol\theta_1 \times \Delta\boldsymbol\theta_2. }$ (96)

Solution 38

The cross product is

$\displaystyle \Delta\boldsymbol\theta_1 \times \Delta\boldsymbol\theta_2 = \begin{bmatrix} 0\\ 0\\ 0.0006 \end{bmatrix}.$ (97)
Therefore
$\displaystyle \boxed{ \frac12 \Delta\boldsymbol\theta_1 \times \Delta\boldsymbol\theta_2 = \begin{bmatrix} 0\\ 0\\ 0.0003 \end{bmatrix}\text{ rad}. }$ (98)

Solution 39

A basic strapdown propagation proceeds as follows:

  1. correct the body gyro measurement using the current sensor calibration and gyro bias estimate;
  2. integrate the corrected gyro data to propagate the quaternion attitude;
  3. use the propagated attitude to rotate measured body specific force into the inertial or navigation frame;
  4. combine the rotated specific force with gravity and any required frame terms;
  5. integrate acceleration to update velocity and then position.

Solution 40

The corrected gyro rate is

$\displaystyle \boldsymbol\omega_c^B = \boldsymbol\omega_m^B-\widehat{\mathbf b}_g = \begin{bmatrix} 0.09\\ 0.18\\ 0.27 \end{bmatrix}$ rad/s$\displaystyle .$ (99)
The delta angle is
$\displaystyle \Delta\boldsymbol\theta = \boldsymbol\omega_c^B\Delta t = \begin{bmatrix} 0.0018\\ 0.0036\\ 0.0054 \end{bmatrix}$ rad$\displaystyle .$ (100)
The first order incremental quaternion is
$\displaystyle \delta q \approx \begin{bmatrix} 1\ 0.0009\ 0.0018\ 0.0027 \end{bmatrix}.$ (101)
Since $q_k$ is the identity,
$\displaystyle q_{k+1} \approx q_k\delta q = \begin{bmatrix} 1\ 0.0009\ 0.0018\ 0.0027 \end{bmatrix}.$ (102)
A production implementation would normally normalize this first order result, or use the exact exponential increment directly.

License

This article is an original synthesis prepared for PhysicsLibrary and intended for release under CC BY-SA 4.0.



"quaternion exercises for physics and engineering" is owned by bloftin.
(view preamble)
View style:
Keywords:  quaternion, rotation, attitude, direction cosine matrix, Euler angles, angular velocity, IMU, exercises, worked solutions

This object's parent.

Cross-references: identity, position, acceleration, calibration, norm, dot product, vector product, force, error quaternion, differential equation, representation, trace, relation, matrix, formula, quaternion product, scalar, velocity, vector, kinematics, direction cosine matrices, quaternion

This is version 1 of quaternion exercises for physics and engineering, born on 2026-08-24.
Object id is 1112, canonical name is QuaternionExercisesForPhysicsAndEngineering.
Accessed 8 times total.

Classification:
Physics Classification02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)
 45.40.-f (Dynamics and kinematics of rigid bodies)
 06.30.Gv (Velocity, acceleration, and rotation)
Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:

No messages.

Interact
rate | post | correct | update request | add example | add (any)