how to solve this first order nonlinear differential equation I'm reading nonlinear control systems book. The author provides this example
$$
\dot{x} = r + x^2, \quad r < 0.
$$
I would like to compute the analytical solution for the proceeding ODE. My attempt is 
$$
\begin{align}
\frac{dx}{dt} &= r + x^2 \\
\frac{dx}{r+x^2} &= dt \\
\int^{x(t)}_{x_0} \frac{1}{r+x^2} dx &= \int^{t}_{t_0} d\tau \\
\frac{\tan^{-1}\left(\frac{x}{\sqrt{r}}\right)}{\sqrt{r}} \Big|^{x(t)}_{x_0} &= (t-t_0)
\end{align}
$$
Now the problem with the assumption that $r<0$, how I can handle the substitution for the left side? I need to reach the final step where $x(t)$ is solely in the left side. 
 A: Let us consider 
$$\dot x=x^2-1$$ for convenience.
When $|x|<1$, we solve the separable equation with
$$\frac{dx}{1-x^2}=-dt$$ and
$$\text{artanh }x-\text{artanh }x_0=t_0-t,$$
i.e.
$$x=\tanh(t_0-t+\text{artanh }x_0).$$
When $|x|>1$, we solve with
$$\text{arcoth }x-\text{arcoth }x_0=t_0-t,$$
i.e.
$$x=\coth(t_0-t+\text{arcoth }x_0).$$
Notice that this solution has a vertical asymptote at $t=t_0+\text{arcoth }x_0$.
Finally, $x=\pm1$ are two valid solutions.

A: Solve it as Riccati equation by setting $x=-\frac{u'}{u}$. Then
$$
u''-a^2u=0
$$
has the solution $u(t)=Ce^{at}+De^{-at}$ and thus
$$
y(x)=-a\frac{Ce^{at}-De^{-at}}{Ce^{at}+De^{-at}}
$$
with some redundancy in the parameter pair $(C,D)$.
A: Let $r=-a^2$. Then
$$\int\frac{dx}{x^2-a^2}=\int dt$$
$$-\frac{\log{\left( x+a\right) }-\log{\left( x-a\right) }}{2 a}=t+c$$
Take $c=\frac{\log C}{2a}$.
$$\log{\left( \frac{x-a}{C\, \left( x+a\right) }\right) }=2 a t,$$
$$\frac{x-a}{x+a}=C\, {{e}^{2 a t}}.$$
General solution is
$$x=\frac{a(1+Ce^{2at})}{1-Ce^{2at}}.$$
A: We use separation of variables to solve the ODE $\dot{x} = r + x^2$, $r < 0$:


*

*We first find the constant solutions $x \equiv \pm \sqrt{-r}$. In the following steps we shall assume $r+x^2 \not \equiv 0$.

*We use the Leibniz notation and we separate the variables: $\frac{dx}{dt} = r + x^2$, $\frac{1}{r+x^2} dx = dt$.

*We integrate on both sides: $\int \frac{1}{r+x^2} \, \mathrm{d}x = \int 1 \, \mathrm{d}t$.

*We solve the integral on the left-hand side using the substitution $x = \sqrt{-r} u$, $dx = \sqrt{-r} du$:
\begin{eqnarray}
\int \frac{1}{r+x^2} \, \mathrm{d}x &=& \int \frac{1}{r-ru^2} \sqrt{-r} \, \mathrm{d}u = \frac{\sqrt{-r}}{r} \int \frac{1}{1-u^2} \, \mathrm{d}u = \frac{\sqrt{-r}}{r} \left\{ \begin{array}{ll}
\operatorname{artanh}(u) + \tilde{C}, & |u| < 1\\
\operatorname{arcoth}(u) + \tilde{C}, & |u| > 1
\end{array}
\right.\\
&=& \frac{\sqrt{-r}}{r} \left\{ \begin{array}{ll}
\operatorname{artanh}\left(\frac{x}{\sqrt{-r}}\right) + \tilde{C}, & |x| < \sqrt{-r}\\
\operatorname{arcoth}\left(\frac{x}{\sqrt{-r}}\right) + \tilde{C}, & |x| > \sqrt{-r}
\end{array}
\right., \quad \tilde{C} \in \mathbb{R}.
\end{eqnarray}
Thus we now obtain the nonlinear equations
\begin{eqnarray}
\operatorname{artanh}\left(\frac{x}{\sqrt{-r}}\right) = C -\sqrt{-r} t, \quad |x| < \sqrt{-r},\\
\operatorname{arcoth}\left(\frac{x}{\sqrt{-r}}\right) = C -\sqrt{-r} t, \quad |x| > \sqrt{-r},
\end{eqnarray}
with a constant $C \in \mathbb{R}$.
Finally, we obtain 4 possible solutions of the ODE, depending on the initial value $x(t_0) = x_0 \in \mathbb{R}$:
\begin{eqnarray}
x(t) &=& \sqrt{-r} \coth\left(\operatorname{arcoth}\left(\frac{x_0}{\sqrt{-r}}\right)-\sqrt{-r}(t-t_0)\right), \quad |x_0| > \sqrt{-r},\\
x(t) &=& -\sqrt{-r}, \quad x_0 = -\sqrt{-r},\\
x(t) &=& \sqrt{-r}, \quad x_0 = \sqrt{-r},\\
x(t) &=& \sqrt{-r} \tanh\left(\operatorname{artanh}\left(\frac{x_0}{\sqrt{-r}}\right)-\sqrt{-r}(t-t_0) \right), \quad |x_0| < \sqrt{-r}.
\end{eqnarray}
