Distribution of $\arctan(X/Y)$ Given $X$ and $Y$ independent random variables with a standard normal distribution, I've been asked to calculate thee distribution of $Z=\arctan(X/Y)$. For that I thought about calculating the cumulative distribution function of $Z$  and then take its derivative.
So $P(Z \leq  t)$ would be:
$$ \iint_{R}^{ } \frac{1}{2\pi } e^{\frac{-(x^{2}+y^{2})}{2}} $$
where $R=\{(x,y) \in \Bbb R : \arctan(x/y) \leq  t)\}$
Then I thought about solving the integral by using polar coordinates, but I'm not sure what the boundaries for $r$ and $\theta$ should be.
 A: You can use a very standard approach, as follows.
First perform a change of variables
$$
\begin{cases}
U = \arctan\left(\frac{X}{Y}\right)\\
V = X.
\end{cases}
$$
If you invert the relationships, they become
$$
\begin{cases}
X = V\\
Y = V\cot U.
\end{cases}
$$
The Jacobian of this transformation is
$$J = \left|
\begin{array}{cc}
0 & 1\\
-\frac{V}{\sin^2 U} & \cot U
\end{array} 
\right| = \frac{V}{\sin^2 U}.$$
The joint distribution of $(U,V)$ is
$$f_{U,V}(u,v) = f_{X,Y}(v,v\cot u) |J|,$$
limited to the correct domain, which we can find by considering the codomain of the functions involved in the original change of variables. In our case, the domain is
$$ D_{U,V}=\left(-\frac{\pi}2; \frac{\pi}2\right) \times  \Bbb R.$$
So we have
$$ f_{U,V}(u,v) = 
\begin{cases}
\frac{1}{2\pi} e^{-\frac{v^2+v^2\cot^2 u}2} \cdot \left|\frac{v}{\sin^2 u}\right| &((u,v) \in D_{U,V})\\
0 & ((u,v) \not\in D_{U,V}),
\end{cases}
$$
that is, with some simplifications,
$$ f_{U,V}(u,v) = 
\begin{cases}
\frac{1}{2\pi} e^{-\frac{v^2}{2\sin^2 u}} \cdot \frac{|v|}{\sin^2 u} &((u,v) \in D_{U,V})\\
0 & ((u,v) \not\in D_{U,V}).
\end{cases}
$$
Finally, by integration we obtain the marginal distribution you need.
$$f_U(u)= \begin{cases} \int_{-\infty}^{+\infty} f_{U,V}(u,v) dv & -\frac{\pi}2 \leq u \leq \frac{\pi}2 \\ 0 & \mbox{otherwise}.\end{cases}\tag{1}\label{1}$$
With the change of variables $t = v^2/2\sin^2 u$ the integral becomes
\begin{eqnarray} 
\int_{-\infty}^{+\infty} f_{U,V}(u,v) dv &=& \frac1{2\pi}\left[\int_0^{+\infty}e^{-t}dt-\int_{-\infty}^0 e^{-t}dt\right]=\\
&=&\frac1{\pi} \int_0^{+\infty}e^{-t}dt = \frac1{\pi}.
\end{eqnarray}
Using \eqref{1} leads to the conclusion that $U$ has uniform distribution between $-\frac{\pi}2$ and $\frac{\pi}2$.

If, instead, you want to use the approach you mention (in this case it's faster), then consider the inequality
$$U = \arctan\left(\frac{X}{Y}\right) < \alpha.$$
If $0\leq \alpha \leq \frac{\pi}2$, the condition is satisfied by the points $(X,Y)$ in the red shaded region (Figure below).

So in this case, using the symmetry of the original distribution, we get, for the CDF of $U$,
\begin{eqnarray}
F_U(\alpha) &=& P(U < \alpha) = \frac1{\pi}\int_0^{+\infty}\int_{\pi/2-\alpha}^{\pi} e^{-\frac{\rho^2}2}\rho d\theta d\rho=\\
&=& \left(\frac12+\frac{\alpha}{\pi}\right)\int_0^{+\infty}e^{-\frac{\rho^2}2}\rho d\rho=\\
&=&\left(\frac12+\frac{\alpha}{\pi}\right).
\end{eqnarray}
If $-\frac{\pi}2 \leq \alpha \leq 0$, the points $(X,Y)$ that satisfy the relationship are in the blue shaded region below.

This gives again
\begin{eqnarray}
F_U(\alpha) &=& P(U < \alpha) = \frac1{\pi}\int_0^{+\infty}\int_{\pi/2-\alpha}^{\pi} e^{-\frac{\rho^2}2}\rho d\theta d\rho=\\
&=&\left(\frac12+\frac{\alpha}{\pi}\right).
\end{eqnarray}
In conclusion,
$$
F_U(\alpha) =
\begin{cases}
\left(\frac12+\frac{\alpha}{\pi}\right) & \left(|\alpha| \leq \frac{\pi}2\right)\\
0 & \mbox{otherwise},
\end{cases}
$$
which clearly is a CDF of a uniform distribution between $-\frac{\pi}2$ and $\frac{\pi}2$.
A: Firstly, we'll find distribution of $W= \frac{X}{Y}$. Consider vector $V = (X,Y)$ with density $f_V(x,y) = \frac{1}{2\pi}e^{-\frac{x^2+y^2}{2}}$.
$F_W(t)= \mathbb P(W \le t) = \mathbb P( \frac{X}{Y} \le t) = \mathbb P( (X \le tY, Y\ge 0) \cup (X \ge tY, Y < 0)) = \mathbb P(X \le tY, Y\ge 0) + \mathbb P( (X \ge tY, Y < 0)= \mathbb P( V \in A_t) + \mathbb P( V \in B_t) = \mu_V(A_t) + \mu_V(B_t)$, where:
$\mu_v(C) = \int_C f_V(v) d\lambda_2(v)$, $A_t = \{ (x,y) \in \mathbb R^2 : y\ge 0, x \le yt\}, B_t = \{ (x,y) \in \mathbb R^2 : y< 0, x \ge yt\}$.
That is:
$\mu_V(A_t) = \frac{1}{2\pi}\int_0^{+\infty} \int_{-\infty}^{yt} e^{-\frac{x^2+y^2}{2}} dxdy$
$ \mu_V(B_t) = \frac{1}{2\pi}\int_{-\infty}^{0} \int_{yt}^{+\infty} e^{-\frac{x^2+y^2}{2}} dxdy $ 
Note, that functions $t \to \mu_V(A_t), t \to \mu_V(B_t)$ are continuosly differentiable, so $F_w$ as a function of $t$ is, too.
We get: $f_W(t) = \frac{dF_W}{dt}(t) = \frac{1}{2\pi}\frac{d}{dt}(\int_0^{+\infty} \int_{-\infty}^{yt} e^{-\frac{x^2+y^2}{2}} dxdy + \int_{-\infty}^{0} \int_{yt}^{+\infty} e^{-\frac{x^2+y^2}{2}} dxdy) $
$ =\frac{1}{2\pi}(\int_0^{+\infty} \frac{d}{dt} \int_{-\infty}^{yt} e^{-\frac{x^2+y^2}{2}}dxdy + \int_{-\infty}^{0} \frac{d}{dt}\int_{yt}^{+\infty} e^{-\frac{x^2+y^2}{2}} dxdy) = $
$= \frac{1}{2\pi}(\int_0^{+\infty}e^{-\frac{y^2}{2}}( \frac{d}{dt}(G(yt) - G(-\infty)) )dy + \int_{-\infty}^0 e^{-\frac{y^2}{2}}( \frac{d}{dt}( G(+\infty) - G(yt)))dy)$, where $G(x) = \int e^\frac{-x^2}{2}dx$. So $\frac{d}{dt}G(yt) = ye^\frac{-(yt)^2}{2}$.
So that we get:
$f_W(t) = \frac{1}{2\pi}(\int_0^{+\infty} ye^{-\frac{y^2(t^2+1)}{2}}dy - \int_{-\infty}^0 ye^{-\frac{y^2(t^2+1)}{2}}dy)$. The same substitution $ w = \frac{y^2}{2} $, gives us:
$f_W(t) = \frac{1}{2\pi}(\int_0^\infty e^{-w(t^2+1)} dw + \int_0^\infty e^{-w(t^2+1)} dw  ) = \frac{1}{\pi} \int_0^\infty e^{-w(t^2+1)}dw = \frac{1}{(t^2+1)\pi}$. Luckily it integrates to one ;).
So now, as we have $W$, we can look at the distribution of $Z=\arctan(W)$
$F_Z(t) = \mathbb P( Z \le t ) = \mathbb P( \arctan(W) \le t) $. So at this point, for $t\le -\frac{\pi}{2}$ we have $F_Z(t) = 0$, and for $t \ge \frac{\pi}{2}$, we have $F_Z(t) = 1$. Let's take any $t \in (-\frac{\pi}{2}, \frac{\pi}{2})$.
$F_Z(t) = \frac{1}{\pi}\int_{-\infty}^{\tan(t)} \frac{1}{(t^2+1)} = \frac{1}{\pi}(\arctan(\tan(t)) - \arctan(-\infty)) = \frac{t}{\pi} + \frac{1}{2}.$
So, taking derivative of $F_Z$ (as we see, it is piecewise continuously differentiable), we have, that the density of $Z$ is $f_Z(z) = \frac{1}{\pi} \chi_{(-\frac{\pi}{2},\frac{\pi}{2})}$, so to conclude $Z \sim \mathcal U((-\frac{\pi}{2},\frac{\pi}{2}))$
A: Hint:  Try to use $\pi/2 - \arctan(y/x)=\arctan(x/y)$.  
If $(x,y) = (r \cos\theta, r\sin\theta)$  where $r>0$ and $\pi/2>\theta>0$ then for any real number $t$, the following are equivalent:


*

*$\arctan(x/y) \leq t$ 

*$\pi/2 - \arctan(y/x) \leq t$

*$\pi/2 - \theta \leq t$

*$\pi/2 - t \leq \theta$
This should help you to get the right limits for the integration.
Also, notice that changing $r$ does not affect whether  $\pi/2 - t \leq \theta$.
