# DSolve not finding solution I expected

Try to solve the following ODE via DSolve

\left\{\begin{aligned} y'(x)+2 y(x) e^x-y(x)^2 &= e^{2 x}+e^x \\ y'(0) &=1 \end{aligned}\right.

The expected solution is $y(x)=e^x$, but Mathematica produces the message:

DSolve::bvfail: For some branches of the general solution, the given boundary conditions lead to an empty solution

Note: $y(x)=e^x$ is obviously a special solution to the original ODE and satisfies the initial/boundary value condition which can be easily verified by substituting it into the ODE.

Additionally, it is easy to deduct that: $y'(0)=1\Leftrightarrow y(0)=1$ for this ODE;

How to handle it?

• I see no reason to worry. There is no problem in letting the constant of Integration C go to infinity. Infinity is just one point in the complex plane. Then the general solution collapses into the "expected" simple exponential. – Dr. Wolfgang Hintze Mar 8 '16 at 11:55

## The problem - Genericity of solutions

The problem we encounter here is that DSolve can return only a generic solution however that general solution cannot satisfy such an initial condition as y' == 1. The issue is related to an arbitrary choice of constants of integration i.e. such constants that are specific to certain types of a differential equations DSolve tries to solve during the integration process.

DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x, y' == 1}, y[x], x]

DSolve::bvnul: For some branches of the general solution, the given boundary conditions
lead to an empty solution. >>

{}


Solving the ODE without the initial condition we will see that the general solution excludes exceptional ones:

y[x_, c_] = y[x] /. First @ DSolve[{ y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x},
y[x], x] /. C -> c

 E^x + 1/(c - x)


Namely there is no constant c reducing the general solution to E^x however putting e.g. y' == 2 we will find a solution:

DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x, y' == 2}, y[x], x]// First

 {y[x] -> (-1 - E^x + E^x x)/(-1 + x)}


This is quite similar issue to one we can find here: Solving a differential equation with initial conditions.

The problem cannot be fixed changing the variables in the ODE to :

y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x /.
{y[x] -> z[x] + E^x, y'[x] -> z'[x] + E^x} // Simplify

z[x]^2 == z'[x]

DSolve[{z'[x] == z[x]^2, z' == 0}, z[x], x]

DSolve::bvnul: For some branches of the general solution, the given boundary conditions
lead to an empty solution. >>

{}


## Remedy

Introducing an initial condition in a general symbolic way we can find also the special solution:

f[x_, c_] = z[x] /. DSolve[{z'[x] == z[x]^2, z' == c}, z[x], x]

 { -(Sqrt[c]/(-1 + Sqrt[c] x)), -(Sqrt[c]/(1 + Sqrt[c] x))}

f[x, c] /. Solve[D[f[x, c] == 0], c]

{ 0, 0}


I.e. we get the special solution y[x] == E^x.

we can see that the same trick can work also in the original equation.

Alternatively the general solution can be reparametrized in a different way:

E^x + c/(1 - x)


yields also the special solution although this excludes e.g. E^x - 1/x

• Can we know how the DSolve works? Is the general solution, $y(x)=e^x+\dfrac{1}{c-x}$, correct? Since $y(x)=e^x$ is obviously a special solution to the ODE, which can be easily verified. – LCFactorization Aug 22 '14 at 10:50
• I mean since $y(x)=e^x$ is a special solution to the ODE, then the ODE with initial condition is not incompatible and the current solving approach DSolve uses may be inappropriate. – LCFactorization Aug 22 '14 at 10:56
• You get the special solution $e^x$ by taking the limit $c \rightarrow \infty$ of the general solution $e^x+\frac{1}{c-x}$. – Stephen Luttrell Aug 22 '14 at 13:10
• @StephenLuttrell This is a useful observation however the problem that DSolve yields generic solutions remains. – Artes Aug 22 '14 at 13:14

Quite often a differential equation may be viewed as an algebraic problem. In such a view, the integration constant C might naturally be viewed as an element of the projective line. But in the natural Mathematica point of view, the constant is taken to belong to an affine subspace, namely the real number line. One could approach finding a solution by taking C to belong to the projective space, via C -> a/b, or by taking it to belong to a different affine subspace, say via C -> 1/C.

In both approaches below, we solve the general differential equation, remap C, and solve the boundary condition for C.

Here is an approach via the projective line, replacing C by the ratio a/b. A potential pitfall here is that a and b are defined only up to a constant of proportionality, but it turns out Solve can handle it in this case.

ysol = First @ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C -> a/b // Simplify
Solve[D[y[x] /. ysol, x] == 1 /. x -> 0, {a, b}]
ysol /. First[%]

(*
{y[x] -> E^x + b/(a - b x)}

Solve::svars: Equations may not give solutions for all "solve" variables. >>
{{b -> 0}}

{y[x] -> E^x}
*)


A better way perhaps is to take a different affine subspace by moving some finite point to infinity. The replacement C -> 1/C moves 0 to infinity (so we lose the solution where the original C == 0). In this formulation there is just one constant to solve for, and at least in this case Solve gets the multiplicity right.

ysol = First @ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C -> 1/C // Together
Solve[D[y[x] /. ysol, x] == 1 /. x -> 0, C]
ysol /. First[%]

(*
{y[x] -> (-E^x - C + E^x x C)/(-1 + x C)}

{{C -> 0}, {C -> 0}}

{y[x] -> E^x}
*)


Update -- General solution comprising all solutions

If we take an even less familiar route and move a non-real, complex number, such as I, to infinity, we can get the solution(s) for all valid initial (real) values for y'[x], which must be at least 1.

ysol = First@ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C -> 1/(C - I) // Together;
Csol = Solve[D[y[x] /. ysol, x] == c /. x -> 0, C];
gensol = {y -> Function @@ #} & /@ Thread[{x, y[x] /. ysol /. Csol // Simplify}]

{y, y'} /. gensol // Simplify               (* initial values *)

y[x] /. gensol /. c -> 1                          (* OP's desired solution *)

(*
{{y -> Function[x, (-Sqrt[-1 + c] + E^x (1 + Sqrt[-1 + c] x))/(1 + Sqrt[-1 + c] x)]},
{y -> Function[x, (Sqrt[-1 + c] + E^x - Sqrt[-1 + c] E^x x)/(1 - Sqrt[-1 + c] x)]}}

{{1 - Sqrt[-1 + c], c}, {1 + Sqrt[-1 + c], c}}  (* initial values *)

{E^x, E^x}                                      (* OP's desired solution *)
*)


Generically, there are two distinct solutions for each initial value for y', but they coincide for y' == 1.

An extended comment that is too long for the comment section.

Amplifying on the comment by Stephen Luttrell:

eqn = y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x;


The generic solution

solnG = DSolve[eqn, y[x], x][[1, 1]]


y[x] -> E^x + 1/(-x + C)

Verifying that the generic solution satisfies the equation

eqn /. NestList[D[#, x] &, solnG, 1] // Simplify


True

Obtaining the special solution requested

solnS = (y[x] -> Limit[y[x] /. solnG, C -> Infinity])


y[x] -> E^x

As expected, the special solution satisfies the equation

eqn /. NestList[D[#, x] &, solnS, 1] // Simplify


True

The requested boundary condition is inherent to the special solution

solnS /. x -> 0


y -> 1

Another remedy is to take the limit as y' -> 1:

sol = DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x, y' == a}, y[x], x];

Limit[y[x] /. sol, a -> 1]

(* {E^x, E^x} *)