# Mathematica unable to solve easy differential equation $y''+y\,y'=0$ with initial conditions $y(0)=1, y'(0)=-1$

Trying to solve the following:

DSolve[{y''[x] + y[x] y'[x] == 0, y[0] == 1, y'[0] == -1}, y[x], x]


leads Mathematica to declare that no analytic solution exists {} along with the error:

DSolve::bvfail: For some branches of the general solution, unable to solve the conditions.

Yet, by performing a very simple substitution of $u = y'$ and solving by hand, we arrive at the remarkably simple solution of $y(x)=\tan\left(\frac{\pi}{4} - \frac{x}{2}\right)$. Indeed, using Maple to compute the solution yields this answer directly. Why is Mathematica unable to solve this DE symbolically while Maple can?

• Nevertheless, it is a NKS - a "new kind of solver", that simply takes longer and solves less problems than Maple as @xzxczd has shown in his link below. :D
– gwr
Apr 12, 2017 at 7:01

It's well known, that DSolve is relatively weak - at least as of now. Frequently we need to help it a bit to obtain the desired solution. In your case, we just need to find the general solution first and then solve for the constant:

generalsol = DSolve[{y''[x] + y[x] y'[x] == 0}, y, x][[1]]

const = Solve[{y[0] == 1, y'[0] == -1} /. generalsol // TrigToExp, {C[1], C[2]},
Method -> Reduce][[1]]

y[x] /. generalsol /. const // Simplify
Simplify[%, C[3] ∈ Integers]
(* Cot[1/4 (π + 2 x)] *)

• Not sure you really mean "common sense" here? :)
– gwr
Apr 12, 2017 at 5:42
• @gwr (Checking the dictionary) Yeah, I mean "common sense" :D . OK, at least it's a common sense among people frequently dealing with differential equation, I think. Apr 12, 2017 at 5:51
• @1110101001 You may find this "interesting": 12000.org/my_notes/kamek/kamke_differential_equations.htm Apr 12, 2017 at 6:46
• @xzczd Wow that confirms what you said. Maple solved 92% while Mathematica got 72%. And maple did them roughly 30x faster. Maybe Wolfram should work on this core before poking fun at maple Apr 12, 2017 at 7:09
• Re English usage: I think the idiom in this case is "common knowledge." Apr 12, 2017 at 11:28

DSolve as of V11, sets the Method option of Solve to Restricted. This probably fixes some things, but it gets in the way here. We can try the Villegas-Gayley trick to override the setting. This does it for all instances of Solve used by DSolve, but it's hard to target the instance that is needed.

InternalInheritedBlock[{Solve},
Unprotect[Solve];
Solve[eq_, v_, opts___] /; ! TrueQ[$in] := Block[{$in = True},
Solve[eq, v, Method -> Automatic, opts]
];
Protect[Solve];
sol = DSolve[{y''[x] + y[x] y'[x] == 0, y[0] == 1, y'[0] == -1}, y[x], x]
]
(*
{{y[x] ->
ConditionalExpression[I Tanh[1/2 (I x + 1/2 I (-π + 8 π C[3]))], C[3] ∈ Integers]}}
*)


This can be simplified as @xzczd does, Simplify[sol, C[3] ∈ Integers].

• Just a side note: this doesn't work in v9 (the output is still {}), modifying Solve[eq, v, Method -> Automatic, opts] to Solve[eq // TrigToExp, v, opts] works though. Apr 12, 2017 at 13:07
• @xzczd Thanks, your fix for V9 will be helpful. Note one still needs to reset Method for it to work in V11: Solve[eq // TrigToExp, v, Method -> Automatic, opts]. Apr 12, 2017 at 16:42

Comment

Maples dsolve is able to solve this IVP without any fuss,

restart:
ode:=diff(y(x),x$2)+y(x)*diff(y(x),x$1)=0;
ics:=y(0)=1,D(y)(0)=-1;
sol:=dsolve({ode,ics},y(x));


plot(rhs(sol),x=0..3);
`
• yeah I noted that in the opening post Apr 12, 2017 at 8:15
• @1110101001 opening post?
– zhk
Apr 12, 2017 at 8:24
• In the body of my question — "...Maple to compute the solution yields this answer directly" Apr 12, 2017 at 9:54
• @1110101001 not a second order ode, you mentioned first order ode which u get after subbing
– zhk
Apr 12, 2017 at 9:59