12

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?

mmal
  • 3,508
  • 2
  • 18
  • 38
1110101001
  • 1,979
  • 13
  • 24
  • 4
    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 07:01

3 Answers3

13

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)] *)
gwr
  • 13,452
  • 2
  • 47
  • 78
xzczd
  • 65,995
  • 9
  • 163
  • 468
  • 1
    Not sure you really mean "common sense" here? :) – gwr Apr 12 '17 at 05:42
  • 2
    @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 05:51
  • Huh, I would have thought that Mathematica's DSolve should be best in the field. Good thing there's always maple as a fallback. – 1110101001 Apr 12 '17 at 06:39
  • 9
    @1110101001 You may find this "interesting": http://12000.org/my_notes/kamek/kamke_differential_equations.htm – xzczd Apr 12 '17 at 06:46
  • 3
    @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 07:09
  • 4
    Re English usage: I think the idiom in this case is "common knowledge." – Michael E2 Apr 12 '17 at 11:28
  • 1
    Re English usage: If it were "common sense", then it would still be just "common sense". Just like there is one common denominator there are not countably many common senses (probably). :) – gwr Apr 12 '17 at 11:56
7

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.

Internal`InheritedBlock[{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].

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 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
4

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));

enter image description here

plot(rhs(sol),x=0..3);
zhk
  • 11,939
  • 1
  • 22
  • 38