Problem of minimum in physics. 
It is necessary to go from a point $A(0,0)$ to a point $B(a,b)$ walking from A to $P(x,0)$ with a speed $v_1$ and then until the point B with a speed $v_2$.
Find where is the point in which it is necessary to abandon x axis in order to have the minimum time to complete the path.
I've called $x$ the distance of A from P.
The function is $$t(x)=\frac{x}{v_1}+\frac{\sqrt{(a-x)^2+b^2}}{v_2}$$
$$\frac{dt}{dx}=\frac{1}{v_1}+\frac{(a-x)*(-1)}{v_2* \sqrt{(a-x)^2+b^2}}=0 \Rightarrow v_2*\sqrt{(a-x)^2+b^2}=v_1*(a-x) \Rightarrow x^2(v_2^2-v_1^2)+x(-2av_2^2+2av_1^2)+(a^2v_2^2+b^2v_2^2-v_1^2a^2)=0$$
The solutions of this equation are $x_{1/2}  =a \pm \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}  $
Putting $\frac{dt}{dx}>0$ it is verified for $0<x<a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$ and for $x>a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$.
So the minimum point is for $a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}$
and  the minimum time is
$$t(a + \frac{v_2 b}{\sqrt{v_1^2-v_2^2}})= \frac{b (v_1^2+v_2^2)}{v_1v_2 \sqrt{v_1^2-v_2^2}}+\frac{a}{v_1}$$
I'm not sure that I haven't done mistakes, because in the solution on the book it indicates
$a  - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}  $  as the solution of minimum.
and  the minimum time
$$t(a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}})= \frac{b\sqrt{v_1^2-v_2^2}}{v_1v_2}+\frac{a}{v_1}$$
but, in particular , it distinguishes the case of $\frac{v_2^2}{v_1^2}\ge \frac{a^2}{a^2+b^2}$
in which the minimum time is possible walking from A to B directly.
 A: You are correct that
$$ \frac{dt}{dx} = \frac{1}{v_1} - \frac{a-x}{v_2 \sqrt{(a-x)^2+b^2}} \tag1$$
and that $\frac{dt}{dx} = 0$ implies
$$ v_2 \sqrt{(a-x)^2+b^2} = v_1 (a-x), \tag2$$
which (I think--I did not check your arithmetic here) implies
$$ x^2(v_2^2-v_1^2)+x(-2av_2^2+2av_1^2)+(a^2v_2^2+b^2v_2^2-v_1^2a^2) = 0. \tag3$$
But you seem to be assuming (incorrectly) that Equation $(3)$ implies Equation $(2)$.
It does not. Equation $(3)$ does imply
$$ v_2 \sqrt{(a-x)^2+b^2} = \pm v_1 (a-x), $$
but this is not the same thing.
Also, the region where the left side of Equation $(3)$ is positive does not correspond to the region where $\frac{dt}{dx}$ is positive.
What Equation $(3)$ gives you is two possible points at which $\frac{dt}{dx}$ might be zero. To determine which points are actual zeros, compare each of them against Equation $(2)$.
Assuming that $v_1$ and $v_2$ both are positive,
in Equation $(2)$ we see that the left side is positive and that
therefore $a - x$ must also be positive.
That is, $x < a.$ Hence of the two roots of Equation $(3)$, the only one that can be a zero of $\frac{dt}{dx}$ is the one that is less than $a,$ namely
$$ x_0 = a - \frac{v_2 b}{\sqrt{v_1^2-v_2^2}}. $$
To determine whether this is a local minimum or a local maximum,
you must examine the sign of $\frac{dt}{dx}$ for values of $x$
less than $x_0$ or greater than $x_0$,
not the values of the left-hand side of Equation $(3).$
A: Your calculations are mostly correct, you just have to interpret the results correctly.
You have a continuous function $t : \Bbb{R} \to \Bbb{R}$ and hence it must attain its minimum on the compact set $[0,a]$ in some point $x_{0} \in [0,a]$.
Moreover, $t$ is differentiable on $\langle 0,a\rangle$ and if it happens that $x_0 \in \langle 0,a\rangle$ then $x_0$ is a local extremum of $t$ so in particular $t'(x_0) = 0$. Assuming $v_1 > v_2$ (if $v_1 \le v_2$, then simply $x_0 = 0$), you correctly found that the possible zeroes of $t'$ are included in $\left\{a- \frac{bv_2}{\sqrt{v_1^2-v_2^2}},a+ \frac{bv_2}{\sqrt{v_1^2-v_2^2}}\right\}$ (as @David K pointed out, the only actual zero of $t'$ is $a- \frac{bv_2}{\sqrt{v_1^2-v_2^2}}$ but it doesn't matter here). Therefore, we conclude that $$x_0 \in \left\{0,a, a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}},a+\frac{bv_2}{\sqrt{v_1^2-v_2^2}}\right\}.$$
However, we are interested only in $x_0 \in [0,a]$. Notice that $a+\frac{bv_2}{\sqrt{v_1^2-v_2^2}} > a$ so this option is certainly wrong.
Moreover, we have
$$a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}} \in [0,a] \iff \frac{bv_2}{\sqrt{v_1^2-v_2^2}} \le a \iff \frac{v_2}{v_1} \le \frac{a}{\sqrt{a^2+b^2}}.$$
Hence if $\frac{v_2}{v_1} \le \frac{a}{\sqrt{a^2+b^2}}$, then $a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}} \in [0,a]$ and this is indeed the minimum point. Namely,
$$t\left(a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}}\right) = \frac{a}{v_1}+\frac{b\sqrt{v_1^2-v_2^2}}{v_1v_2}$$
which is smaller than both $t(0)$ and $t(a)$. We can use Cauchy-Schwarz:
$$\frac{a}{v_1}+\frac{b\sqrt{v_1^2-v_2^2}}{v_1v_2}\le \sqrt{a^2+b^2}\sqrt{\frac{1}{v_1^2}+\frac{v_1^2-v_2^2}{v_2^2}} = \frac{\sqrt{a^2+b^2}}{v_2} = t(0),$$
$$\frac{a}{v_1}+\frac{b}{v_2} \cdot \underbrace{\frac{\sqrt{v_1^2-v_2^2}}{v_1}}_{\le 1} \le \frac{a}{v_1}+\frac{b}{v_2} = t(a).$$
On the other hand, if $\frac{v_2}{v_1} > \frac{a}{\sqrt{a^2+b^2}}$, then this point is not in $[0,a]$ so it has to be simply $x_0 = 0$ or $x_0 = a$. It is not hard to see that
$$t(0) \le t(a) \iff \frac{\sqrt{a^2+b^2}}{v_2} \le \frac{a}{v_1}+\frac{b}{v_2} \iff \frac{v_2}{v_1} \ge \frac{\sqrt{a^2+b^2}-b}a$$
and the latter is true in our case since
$$\frac{v_2}{v_1} > \frac{a}{\sqrt{a^2+b^2}} \ge  \frac{\sqrt{a^2+b^2}-b}a.$$
So it has to be $x_0 = 0$.
Therefore:
$$x_0 = \begin{cases}
a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}}, &\text{ if } \frac{v_2}{v_1} \in \left\langle 0, \frac{a}{\sqrt{a^2+b^2}}\right] \\ 
0, &\text{ if } \frac{v_2}{v_1} \in \left[\frac{a}{\sqrt{a^2+b^2}}, 1\right\rangle \\ 
\end{cases}$$
If $v_1 >> v_2$ then $x_0$ approaches $a$, namely
$$\lim_{\frac{v_2}{v_1} \to 0} \left(a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}}\right) = \lim_{\frac{v_2}{v_1} \to 0} \left(a-\frac{b}{\sqrt{\left(\frac{v_1}{v_2}\right)^2-1}}\right) = a$$
but it is always faster to go at least somewhat diagonally than straight left and then straight up.
On the other hand, if $v_1$ approaches $v_2$ then you may wonder why
$$\lim_{\frac{v_2}{v_1} \to 1} \left(a-\frac{bv_2}{\sqrt{v_1^2-v_2^2}}\right) = -\infty$$
and not $0$ but this expression stops being relevant as soon as $\frac{v_2}{v_1} \ge \frac{a}{\sqrt{a^2+b^2}}$ as is it is faster to simply go diagonally.
