12
$\begingroup$

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?

$\endgroup$
1
  • 4
    $\begingroup$ 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 $\endgroup$
    – gwr
    Apr 12, 2017 at 7:01

3 Answers 3

13
$\begingroup$

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)] *)
$\endgroup$
7
  • 1
    $\begingroup$ Not sure you really mean "common sense" here? :) $\endgroup$
    – gwr
    Apr 12, 2017 at 5:42
  • 2
    $\begingroup$ @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. $\endgroup$
    – xzczd
    Apr 12, 2017 at 5:51
  • 9
    $\begingroup$ @1110101001 You may find this "interesting": 12000.org/my_notes/kamek/kamke_differential_equations.htm $\endgroup$
    – xzczd
    Apr 12, 2017 at 6:46
  • 3
    $\begingroup$ @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 $\endgroup$
    – 1110101001
    Apr 12, 2017 at 7:09
  • 4
    $\begingroup$ Re English usage: I think the idiom in this case is "common knowledge." $\endgroup$
    – Michael E2
    Apr 12, 2017 at 11:28
7
$\begingroup$

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].

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – xzczd
    Apr 12, 2017 at 13:07
  • $\begingroup$ @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]. $\endgroup$
    – Michael E2
    Apr 12, 2017 at 16:42
4
$\begingroup$

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);
$\endgroup$
4
  • $\begingroup$ yeah I noted that in the opening post $\endgroup$
    – 1110101001
    Apr 12, 2017 at 8:15
  • 1
    $\begingroup$ @1110101001 opening post? $\endgroup$
    – zhk
    Apr 12, 2017 at 8:24
  • 1
    $\begingroup$ In the body of my question — "...Maple to compute the solution yields this answer directly" $\endgroup$
    – 1110101001
    Apr 12, 2017 at 9:54
  • $\begingroup$ @1110101001 not a second order ode, you mentioned first order ode which u get after subbing $\endgroup$
    – zhk
    Apr 12, 2017 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.