I am a mechanical engineering student, and I am trying to solve the following ODE:
$$\frac{1}{2}f''=f^3 - f$$
where $f=f(x)$ and the boundary conditions are $f(0)=0$ and $f'(\infty)=0$. On the Wolfram Mathworld page for the hyperbolic tangent, it is remarked that the solution to this ODE is given by $f=\tanh(x)$. This can easily be verified by substitution, but I am looking for a step-by-step procedure to get to the solution.
I have tried using the substitution $g=f'$, which yields $$ g' = \frac{dg}{dx}=\frac{dg}{df} \frac{df}{dx}=\frac{dg}{df}f'=\frac{dg}{df}g$$
Using $f''=g'$, the substitution of the expresion above in the ODE leads to $$\frac{1}{2} g dg = (f^3-f) df$$
which can be integrated to yield $$\frac{1}{4} (f')^2 = \frac{1}{4}f^4-\frac{1}{2}f^2 + C$$
At this point, I am stuck and I do not know how to proceed. Any help would be greatly appreciated!
Best regards, Nick
Update 1: Thanks to Mattos' answer, I realised that I can write the final expression as (I already use here $C=0$, although I am not completely sure if that is allowed already):
$$\frac{df}{f\sqrt{f^2-2}} = dx$$
Using the following expression I found on sosmath (using different symbols to avoid confusion):
$$\int \frac{dh}{h \sqrt{h^2-a^2}}=\frac{1}{a}\sec^{-1}\left|\frac{h}{a}\right|$$
we can integrate to find: $$\frac{1}{\sqrt{2}} \sec^{-1}\left|\frac{f}{\sqrt{2}}\right|=x$$
which is definitely a lot closer to the answer I am looking for. Any help to go from here to $\tanh$ is appreciated. I will make sure to post the answer if I figure it out. Thanks!
Update 2: I am not sure if the above approach will lead to the correct answer. However, an extensive derivation is given in the answers by LutzL. Thanks for the help!
Multiply through with $4f'$ and integrate to get $$ (f')^2=f^4-2f^2+C $$ in a shorter way.
For a twice continuously differentiable function, $f'(∞)=0$ implies that all higher derivatives also vanish. This gives for the value at infinity $$ 0=\frac12f''(∞)=f(∞)(f(∞)^2-1)\text{ and }0=(f'(∞))^2=f(∞)^4-2f(∞)^2+C $$ which gives the variants $f(∞)=0$ and the symmetric $f(∞)=\pm1$ (note that for any solution $f$, also $-f$ is a solution).
Or put in a physical way, $f''=-V'(f)$ with the potential function $V(y)=-(y^2-1)^2$. The "particle" obeying this law of motion starts in the local minimum at $y=0$ and is supposed to come to rest at infinity. This is only possible if it stays at the minimum or approaches asymptotically one of the maxima at $y=\pm 1$.
The first variant implies $C=0$, and that the zero solution is the single and unique solution for these conditions.
$f(∞)=1$ implies $C=1$ and thus $$ f'=\pm(f^2-1) $$ Since the solution starts at $0$, and $f\equiv\pm1$ are solutions of this first order ODE, $|f|<1$. To get a solution growing from $0$ to $1$ you need the negative sign, that is $$ f'(x)=1-f(x)^2\\\implies\\ \frac{f'(x)}{1+f(x)}+\frac{f'(x)}{1-f(x)}=2 \\ \implies\\\ln|1+f(x)|-\ln|1-f(x)|=2x+2C \\\implies\\ f(x)=\frac{e^{2x+2C}-1}{e^{2x+2C}+1}=\frac{e^{x+C}-e^{-(x+C)}}{e^{x+C}+e^{-(x+C)}} $$