Mathematica unable to solve easy differential equation $y''+y\,y'=0$ with initial conditions $y(0)=1, y'(0)=-1$
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)] *)
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]
.
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);