Answer
After 36 years.
Work Step by Step
$ A=P(1+r)^{t}$
is the balance after investing the amount P for t years at a rate r, and compounding is done once a year.
$ A_{1}=4000(1+0.03)^{t},\quad A_{2}=2000(1+0.05)^{t}$.
We want $t$ for which $ A_{1}=A_{2}.$
$ 4000(1.03)^{t}=2000(1.05)^{t}\qquad $ ... $/\displaystyle \times\frac{1}{2000\cdot(1.03)^{t}}$
$ 2=(\displaystyle \frac{1.05}{1.03})^{t}\qquad $ ... $/\log(...)$
$\displaystyle \log 2=t\log\frac{1.05}{1.03}$
$ t=\displaystyle \frac{\log 2}{\log\frac{1.05}{1.03}}\approx 36.0425425489$