# How can I solve this non-linear differential equation?

I'm trying to solve the equation $$y' = 1 - y^2$$ Here is my attempt: $$y' = 1 - y^2$$ Divide by (1-y^2) $$\frac{y'}{1-y^2} = 1$$ Integrate both sides: $$\frac{1}{2}\log|\frac{y+1}{y-1}|=t+c$$ Rearrange $$y = \frac{ke^{2t}+1}{ke^{2t}-1}$$ I'd have thought that solution was right, but we have to figure out a specific solution with y(0) = 0. But this isn't possible with the above equation.

-
Doesn't $y(0)=0$ imply $k=-1$? –  lhf May 19 '11 at 13:41
While I was writing this, I rewrote $e^{2c}$ = $k$. Am I allowed to set k to -1? –  Hannesh May 19 '11 at 13:44
+1 for showing your work. No, working in the reals, you cannot have $k=-1$ when it came from $e^{2c}$. Good for you to keep track of that-it is easy to miss. –  Ross Millikan May 19 '11 at 13:56
@Ross, @Luboš: I don't think complex numbers are the issue here. When seeking real-valued solutions, one can indeed stay completely within the real realm, if one handles the absolute value signs correctly. (Cont.) –  Hans Lundmark May 19 '11 at 16:40
(Cont.) From the integrated expression it follows that $\left| \frac{y+1}{y-1} \right| = \exp 2(t+c)$, hence $\frac{y+1}{y-1} = \pm e^{2c} e^{2t}$. Now let $k = \pm e^{2c}$; then $k$ can be anything except zero. By letting $k$ run through the nonzero real numbers, you get all the real-valued solutions $y(t)$, except the constant ones $y(t)=1$ and $y(t)=-1$ which should have been noted separately before dividing by $1-y^2$. –  Hans Lundmark May 19 '11 at 16:40

Since you want a solution near $y=0$, you should use $1-y$ in the denominator (as it will be positive) and can remove the absolute value signs. This changes some signs in your answer, giving $$y = \frac{ke^{2t}-1}{ke^{2t}+1}$$ and $k=1$ gives $y(0)=0$

-
I thought this wasn't legal since k came from $e^{2c}$ (finding c would involve the log of a negative number) however I realized that there is no reason why c can't be complex. –  Hannesh May 19 '11 at 13:54
Dear @Hannesh, it's not only legal but mandatory to allow all integration constants throughout the calculation being arbitrary complex numbers. Solving equations - algebraic or differential - in the reals isn't simpler than in complex numbers. Quite on the contrary, it's more complicated because you must solve it using all possible complex values of the parameters, and at the very end, you must do an extra job of filtering out the solutions that are not real. See the exchanges right under your question. –  Luboš Motl May 19 '11 at 14:06
See Hans's comment above. There's no need for complex valued integration constants here as long as you don't ignore the absolute value. –  cch May 19 '11 at 19:58

Reducing from what you have a little more, we get that equal to Tanh[x-k].

Tanh[-k] == 0 //Seting x to zero

Therefore k = 0, leaving Tanh[x] as your function.

-
Exactly, this is the right compact form of the solution. tanh is sinh/cosh so its derivative is $(\cosh^2 t - \sinh^2 t)/\cosh^2 t = 1/\cosh^2 t$ which is equal to $1-\tanh^2 t$, indeed. –  Luboš Motl May 19 '11 at 14:04

I wrote it down and solved it in a slightly different way. The first thing you should notice is that $y = 1$ and $y = -1$ are the two constant solutions, which allows you then to divide $y'$ by $1-y^2$, since you want to study it for $y(0) \in (-1,1)$, knowing that any solution starting in $(-1,1)$ stays there (or dies in 1).

Then yes, with some algebra you manage to get

$\left(\log \frac{1+y}{1-y}\right)' = 2$

if I haven't screwed up with the signs; now integrating it from 0 to $t$ you get:

$\log \frac{1+y(t)}{1-y(t)} - \log \frac{1+y(0)}{1-y(0)} = 2t$

without the absolute value since everything in the argument of the logs is non-negative. By imposing $y(0) = 0$ the second term in the left vanishes and you're left with an easy expression that if inverted gives the following:

$y(t) = \frac{e^{2t} - 1}{e^{2t} + 1}$

which is simply

$y(t) = \tanh (t)$

and of course double checking $y(0) = 0$.

-