# Derivation of $\tanh$ solution to $\frac{1}{2}f''=f^3 - f$

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!

• I think it should be $\frac{1}{4}(f')^2$ in the last expression. – SchrodingersCat Feb 24 '16 at 13:16
• You are correct, I just edited the question. Thank you! – Nick J Feb 24 '16 at 13:18
• Often, a simple way to solve linear ODEs with a 'gap' of two derivatives (i.e $f''$ and $f$) is by multiplying through by the derivative that lies between said derivatives (in this case $f'$) and integrating. As you have it in the form $$(f')^{2} = f^{2} ( f^{2} - 2 )$$ notice that this is separable so that you get $$\frac{df}{f \sqrt{f^{2} - 2}} = dx$$ which you can then integrate. Notice that using your conditions implies $C = 0$. – Mattos Feb 24 '16 at 13:53
• @Mattos: This is the shorter way, but you left out the integration constant while integrating $2f''f'=4(f^3-f)f'$. And probably mixed up some constants. – LutzL Feb 24 '16 at 13:56
• In the update, you again forgot the integration constant. However, before that at first you also have to care for division by zero in view that $f(0)=0$. -- Additionally, $f'^2=f^2(f^2-2)$ can only be true for $f\equiv 0$ or $|f|\ge 2$, where only the first, trivial solution is relevant to the problem. – LutzL Feb 24 '16 at 14:58

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)}}$$

• I don't see where you get that $f'(\infty)=0$ implies higher derivatives vanish. What of something like $\sin(1/x)/x$? – Ian Feb 24 '16 at 14:23
• Sorry, I mixed up my example (part of my design was at 0, part at infinity). A correct example of my point would be $f'(x)=\sin(x^3)/x$. – Ian Feb 24 '16 at 14:39
• Yes, that seems like a shortcut. Notice first that the solution has to be bound between the maxima at $\pm1$ of the potential function $V(f)=-(f^2-1)^2$, else the velocity at infinity will not be zero. Differentiate the original equation to get $f'''=2f'(3f^2-1)$ to conclude $f'''(∞)=0$ (this extends to higher derivatives). This implies that $f''(∞)$ exists and $f'(∞)=0$ can only happen if also $f''(∞)=0$. – LutzL Feb 24 '16 at 14:50
• Rephrasing your last sentence to be clearer to others: if $f''(\infty)$ exists and $f'(\infty)$ exists and is finite then $f''(\infty)=0$. Merely having $f'(\infty)$ exist and be finite is not enough for $f''(\infty)$ to exist, however, as my example illustrates. – Ian Feb 24 '16 at 14:52
• This indeed seems to be the correct derivation, thank you very much! – Nick J Feb 24 '16 at 15:25

Let $f' =v(f)$ then $f'' =v'v$ so you get a equation $$\frac{v'v}{2} =f^3 -f$$ hence $$\frac{v^2}{2} =\frac{f^4}{4} -\frac{f^2}{2} +C$$
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://math.stackexchange.com/questions/1670143/derivation-of-tanh-solution-to-frac12f-f3-f", "fetch_time": 1558882701000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2019-22/segments/1558232259316.74/warc/CC-MAIN-20190526145334-20190526171334-00362.warc.gz", "warc_record_offset": 542850197, "warc_record_length": 35920, "token_count": 1866, "char_count": 5570, "score": 4.21875, "int_score": 4, "crawl": "CC-MAIN-2019-22", "snapshot_type": "longest", "language": "en", "language_score": 0.8746790289878845, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00017-of-00064.parquet"}