Let $X \sim U(-1, 1)$ and $X \sim U(-1,1)$. We want to find density function of $W = \sqrt{X^2 + Y^2}$.
I got stuck and I have no idea, where I am making a mistake. This is my approach.
Let $F$ be a cumulative distribution function of $W = \sqrt{X^2 + Y^2}$
\begin{align*} F(w) = P(W \le w ) &= P(\sqrt{X^2 + Y^2} \le w) \\ &= P(X^2 + Y^2 \le w^2) \\ &= \iint \limits_{x^2 + y^2 \le w^2} \frac{1}{4} dxdy \\ &= \int \limits_{0}^{w^2} \int \limits_{0}^{2 \pi} \frac{1}{4} d\theta dr \\ &= \pi \frac{w^4}{4} \end{align*} So, the density: $$ f(w) = F'(w) = \pi w^3 $$
But if I run a simulation:
X <- runif(100000, -1, 1)
Y <- runif(100000, -1, 1)
R2 <- X^2 + Y^2
R <- sqrt(R2)
hist(R, prob=TRUE)
Where am I making a mistake?