# Wahba's problem

In applied mathematics, Wahba's problem, first posed by Grace Wahba in 1965, seeks to find a rotation matrix (special orthogonal matrix) between two coordinate systems from a set of (weighted) vector observations. Solutions to Wahba's problem are often used in satellite attitude determination utilising sensors such as magnetometers and multi-antenna GPS receivers. The cost function that Wahba's problem seeks to minimise is as follows:

${\displaystyle J(\mathbf {R} )={\frac {1}{2}}\sum _{k=1}^{N}a_{k}\|\mathbf {w} _{k}-\mathbf {R} \mathbf {v} _{k}\|^{2}}$

where ${\displaystyle \mathbf {w} _{k}}$ is the k-th 3-vector measurement in the reference frame, ${\displaystyle \mathbf {v} _{k}}$ is the corresponding k-th 3-vector measurement in the body frame and ${\displaystyle \mathbf {R} }$ is a 3 by 3 rotation matrix between the coordinate frames.[1] ${\displaystyle a_{k}}$ is an optional set of weights for each observation.

A number of solutions to the problem have appeared in literature, notably Davenport's q-method, QUEST and singular value decomposition-based methods. This is an alternative formulation of the Orthogonal Procrustes problem (consider all the vectors multiplied by the square-roots of the corresponding weights as columns of two matrices with N columns to obtain the alternative formulation).

Several methods for solving Wahba's problem are discussed by Markley and Mortari.

## Solution by Singular Value Decomposition

One solution can be found using a singular value decomposition as reported by Markley

1. Obtain a matrix ${\displaystyle \mathbf {B} }$ as follows:

${\displaystyle \mathbf {B} =\sum _{i=1}^{n}a_{i}\mathbf {w} _{i}{\mathbf {v} _{i}}^{T}}$

2. Find the singular value decomposition of ${\displaystyle \mathbf {B} }$

${\displaystyle \mathbf {B} =\mathbf {U} \mathbf {S} \mathbf {V} ^{T}}$

3. The rotation matrix is simply:

${\displaystyle \mathbf {R} =\mathbf {U} \mathbf {M} \mathbf {V} ^{T}}$

where ${\displaystyle \mathbf {M} =\operatorname {diag} ({\begin{bmatrix}1&1&\det(\mathbf {U} )\det(\mathbf {V} )\end{bmatrix}})}$

## Code

Matlab functions solving the sightly more general problem of absolute orientation:

## Notes

1. ^ The rotation ${\displaystyle \mathbf {R} }$ in the problem's definition transforms the body frame to the reference frame. Most publications define rotation in the reverse direction, i.e. from the reference to the body frame which amounts to ${\displaystyle \mathbf {R} ^{T}}$.