How do I propagate relative uncertainty through atan2?

196 Views Asked by At

I've got $y = \sin(\theta)$ and $x = \cos(\theta)$ with some relative error on both. If I compute $\theta$ with $\theta = \operatorname{atan2}(y,x)$, how do I propagate the relative error from the inputs to a relative error on the angle?

1

There are 1 best solutions below

3
On BEST ANSWER

The mapping from polar to Cartesian is

$$\binom xy = \binom{r\cos \theta}{r\sin \theta}$$

with total differential

$$ \binom{dx}{dy} =\binom{\cos\theta\,dr-r\sin\theta\,d\theta}{\sin\theta\,dr+r\cos\theta\,d\theta} =\underbrace{\begin{pmatrix} \cos\theta & -r\sin\theta \\ \sin\theta & r\cos\theta \end{pmatrix}}_{\textstyle=:M} \binom{dr}{d \theta} $$ The matrix $M$ encodes how small changes in $r$ and $\theta$ translate to small changes in $x$ and $y$.

If you are mapping the other way, then

$$\binom{dr}{d \theta} = M^{-1}\binom{dx}{dy}$$

So all you have to do is to invert $M$ because using $\operatorname{atan2}(y,x)$ just gives you the $\theta$-coordinate for cartesian $(x,y)$. Notice that this just gives you the ideal error propagation and does not care for gory detail of your atan2 implementation.

More spacifically,

$$M^{-1} = \frac 1{|M|}\begin{pmatrix} r\cos\theta & r\sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix} = \begin{pmatrix} \cos\theta & \sin\theta \\ -\dfrac1r\sin\theta & \dfrac1r\cos\theta \end{pmatrix} $$

so that $$d\theta = \frac1r (-\sin\theta ~~ \cos\theta) \binom{dx}{dy} $$

Maybe you find it more useful to express the derivative in terms of $x$ and $y$. In that case:

$$d\theta = \frac1{x^2+y^2} (-ydx +xdy)$$

See here for example. Thus for $\delta\theta$:

$$\delta\theta^2 = \frac1{(x^2+y^2)^2}(y^2\delta x^2 + x^2\delta y^2)$$

In the case where $\delta x_r=\delta x/x$ denotes the relative error:

$$\delta\theta^2 = \frac{x^2y^2}{(x^2+y^2)^2}(\delta x_r^2 + \delta y_r^2)$$