I am trying to solve the following question:
$p$ and $q$ are two points chosen at random between $0$ & $1$. What is the probability that the ratio $\frac pq$ lies between $1$ & $2$.
There exists a simple graphical method to solve this question that I understood but I tried to solve it using random variables but am getting the wrong answer. Here is what I did:
Let $p$ and $q$ be random variables such that $p$~$Unif(0,1)$ and $q$~$Unif(0,1)$. Let $f_q(x)$ be
$$=>P(\frac pq \in[1,2])=P(\frac pq \leqslant 2)-P(\frac pq \leqslant1)$$
$$=>P(\frac pq \in[1,2])=\int_0^1P(\frac pq \leqslant2|q=x)f_q(x)dx - \int_0^1P(\frac pq \leqslant1|q=x)f_q(x)dx$$
$$=>P(\frac pq \in[1,2])=\int_0^1P(\frac px \leqslant2|q=x)f_q(x)dx - \int_0^1P(\frac px \leqslant1|q=x)f_q(x)dx$$
$$=>P(\frac pq \in[1,2])=\int_0^1P(p \leqslant2x|q=x)f_q(x)dx - \int_0^1P(p \leqslant x|q=x)f_q(x)dx$$
(Since $f_q(x)=1$ as it is pdf of Uniform Distribution)
$$=>P(\frac pq \in[1,2])=\int_0^1P(p \leqslant2x)dx - \int_0^1P(p \leqslant x)dx$$
$$=>P(\frac pq \in[1,2])=\int_0^12xdx - \int_0^1xdx$$
$$=>P(\frac pq \in[1,2])=2 [\frac{x^2}2]_0^1-[\frac {x^2}2]_0^1$$
$$=>P(\frac pq \in[1,2])=1-\frac 12$$
$$\fbox {$=>P(\frac pq \in[1,2])=\frac 12$}$$
But the correct answer is $\frac 14$. What I am doing wrong?
In the step where you turn your probabilities into functions, you set
$$P(p \leqslant x) = x$$
That's totally correct - take a look at the graph and convince yourself of that.
But then take a look at the claim that
$$P(p \leqslant 2x) = 2x$$
If you draw a graph of this, you should be able to convince yourself that something is wrong. For one thing, when $x = 1$, you're getting a probability that's greater than $1$.
Hint: You might want to break $$\int_0^1P(p \leqslant2x)dx$$ into two pieces.