# 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 == 1, y' == -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 '17 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][]

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

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

• Not sure you really mean "common sense" here? :) – gwr Apr 12 '17 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. – xzczd Apr 12 '17 at 5:51
• @1110101001 You may find this "interesting": 12000.org/my_notes/kamek/kamke_differential_equations.htm – xzczd Apr 12 '17 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 – 1110101001 Apr 12 '17 at 7:09
• Re English usage: I think the idiom in this case is "common knowledge." – Michael E2 Apr 12 '17 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 == 1, y' == -1}, y[x], x]
]
(*
{{y[x] ->
ConditionalExpression[I Tanh[1/2 (I x + 1/2 I (-π + 8 π C))], C ∈ Integers]}}
*)


This can be simplified as @xzczd does, Simplify[sol, C ∈ 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. – xzczd Apr 12 '17 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]. – Michael E2 Apr 12 '17 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 – 1110101001 Apr 12 '17 at 8:15
• @1110101001 opening post? – zhk Apr 12 '17 at 8:24
• In the body of my question — "...Maple to compute the solution yields this answer directly" – 1110101001 Apr 12 '17 at 9:54
• @1110101001 not a second order ode, you mentioned first order ode which u get after subbing – zhk Apr 12 '17 at 9:59