I am really rusty in terms of my math skills, and I am pretty sure I must have made a mistake along the lines. I plotted the ratio of those 2 density functions p(x|w1) and p(x|w2) and draw the threshold at 2. Based on this plot, I am expecting the values of x to be ~4 and ~17. However, the solution I get yields totally different results
x = 5.581158889477388
x = -36.6922700005885
It would be nice if you could give me some feedback of what could have gone wrong here!

EDIT:
Just saw that it should be 40x in (6) and thus -260x in (8), but the results are still weird.
Thanks a lot for the nice answers. Very helpful! For future reference: I just updated my equations with the right solution:

First of all, I plotted your original function to see whereabouts the roots defining the $x$ interval where the inequality is true ought to be (you said you did this already).
Taking the right-hand side of (3) over to the left-hand side we have $$ g(x) = \frac{1}{\sqrt{2\pi5 }}\exp\left(-\frac12\frac{(x-15)^2}{5}\right) -2\frac{1}{\sqrt{2\pi10}}\exp\left(-\frac12\frac{(x-20)^2}{10}\right) $$ We want $g(x)>0$
Using R, which is free to download and use
This confirms that we have $g(x)>0$ somewhere in the range $x=0$ to $x=20$. Let's zoom into the range $x\in[2.5,17.5]$ and plot again. The right root is easy to see. But it turns out that the left root isn't too easy to see so we zoom in for a 3rd time to see where that one is.
So we do have roots at $x\approx4$ and $x\approx17$. It helps to know the answer in advance before we start converting this to a quadratic, to help check our work. The R function
unirootwill find a root in a given interval. Let's look in the intervals $[3,4]$ and $[15,17.5]$.gives the output
and
gives the output
So now let's solve the equation analytically, starting from your line (3)
$$\begin{align} \frac{1}{\sqrt{2\pi5 }}\exp\left(-\frac12\frac{(x-15)^2}{5}\right) &> 2\frac{1}{\sqrt{2\pi10}}\exp\left(-\frac12\frac{(x-20)^2}{10}\right)\\ \frac{1}{\sqrt{2\pi5 }}\exp\left(-\frac12\frac{(x-15)^2}{5}\right) &> 2\frac{1}{\sqrt{2}\sqrt{2\pi5}}\exp\left(-\frac12\frac{(x-20)^2}{10}\right) \;\;\;\because \sqrt{10}=\sqrt{5}\sqrt{2}\\ \frac{1}{\sqrt{2\pi5 }}\exp\left(-\frac12\frac{(x-15)^2}{5}\right) &> \sqrt{2}\frac{1}{\sqrt{2\pi5}}\exp\left(-\frac12\frac{(x-20)^2}{10}\right) \;\;\;\;\;\because 2/\sqrt{2}=\sqrt{2}\\ \exp\left(-\frac12\frac{(x-15)^2}{5}\right) &> \sqrt{2}\exp\left(-\frac12\frac{(x-20)^2}{10}\right) \;\;\;\;\;\;\;\;\;\;\;\;\text{cancelling } 1/\sqrt{2\pi5}\\ \end{align}$$
I've taken very small steps to avoid making mistakes, and so far, my workings match yours. We take logs, noting $\ln\sqrt{2} = \ln2^{1/2} = \frac{1}{2}\ln2$. The first line $(\dagger)$ is the same as your equation (4), because $\ln(2)+\ln(1/\sqrt{2})=\ln(2/\sqrt{2})=\ln\sqrt{2}=\frac12\ln2$.
After the first line we multiply by $-20$, reversing the inequality in the process. This is where you went wrong. You made two mistakes here:
On the left hand side, the coefficient of $(x-15)^2$ on line (4) is $-1/10$. Multiplying this by $-20$ gives $2$ not $10$.
On the right hand side, the coefficient of the $\ln$s was 1. Multiplying this by $-20$ gives $-20$ not $+20$. In my case, $\frac12\ln2$ becomes $-10\ln2$.
Apart from the slip you noted on line (6), the rest of your working looks fine, but these mistakes carried through. I've carried on to the same point as you did in your question: up to getting a quadratic (from there I guess you intended to use the formula).
$$\begin{align} -\frac{(x-15)^2}{10} &> \frac{1}{2}\ln{2} - \frac{(x-20)^2}{20} \;\;\;(\dagger)\\ 2(x-15)^2 &< (x-20)^2 - 10\ln2\\ 2(x^2-30x+225) &< (x^2 -40x +400) - 10\ln2\\ 2x^2-60x+450 &< x^2 -40x +400 - 10\ln2\\ x^2-20x+50 + 10\ln2&< 0\\ \end{align}$$
Now let's plot $f(x)$. What we hope are that the $x$ interval defining the area under this graph matches the interval defining the area above the previous graph we had for $g(x)$. If you recall we had $g(x)>0$ for $x\in[3.4374,16.5627]$.
This looks promising: it seems like the interval is going to be the same. But let's just check the roots, to be sure.
gives
and
gives
These are the same to within numerical accuracy, so we can be pretty sure that the derivation is correct.
Footnote
I could have just put together an answer showing only the analytic steps to get to the final quadratic inequality. However, in trying to do so, I made a bunch of errors, and I ended up using R to plot the original graph to see where the roots ought to be so that I could check my analytical steps.
Note, at any stage in the derivation you can plot the inequality to see where you've gone wrong. So you could have plotted your line (4), seen that it was consistent with line (3), and then plotted your line (5) and seen that it was inconsistent with line (4). Or, an easier way would have been to have plugged the roots found using
unirootinto each step.For example with the smaller root, your line (4) gives
1.750256e-05$\approx0$ frombut your line (5) gives
1055.693$\neq0$ fromSo I've shown all my workings with R because if you're prone like me to making unforced errors, it can be really helpful to use a tool to check your work as you're going along.