# DSolve does not return a solution when initial condition is added

Consider the following equation $$y''(x) = -2e^{-y}.$$

The following code

DSolve[y''[x] == -2 Exp[-y[x]], y[x], x] //FullSimplify


returns

{{y[x] -> Log[(2 (-1 + Cosh[Sqrt[C[1]] (x + C[2])]))/C[1]]},
{y[x] -> Log[(2 (-1 + Cosh[Sqrt[C[1]] (x + C[2])]))/C[1]]}}


(They the same solution. Let's ignore that first.) If I impose an initial condition $$y(0) = 0$$ then Mathematica fails to return a solution

DSolve[{y''[x] == -2 Exp[-y[x]], y[0] == 0}, y[x], x]


with the error message

DSolve::bvfail: For some branches of the general solution, unable to solve the conditions.

But a solution does exist. One can choose $$C[1] = 1$$ and $$C[2] = \cosh^{-1}(3/2)$$ in the solution and verify that $$y(0) = 0$$.

Any idea why is this the case?

• So you're mainly interested in the reason why bvfail pops up, rather than a workaround, right? – xzczd Feb 3 '19 at 4:16
• Basically, you are asking why DSolve behaves as it does, and only Wolfram, Inc. can answer that. Suffice it to say that DSolve fails at solving many seemingly simple ODEs. By the way, it also is strange that the two solutions are identical. – bbgodfrey Feb 3 '19 at 4:54
• @bbgodfrey Actually v9.0.1 only gives one solution for the first code piece. The warning is the same though. – xzczd Feb 3 '19 at 5:57
• @xzczd I am also interested into a workaround if it is not human looking at the solution of the general form, doing some calculations and imposing a constraint on C[1] and C[2] – user58955 Feb 3 '19 at 7:03
• @xzczd Yes I am mainly interested in why bvfail pops up – user58955 Feb 3 '19 at 7:04

If you differentiate the ode you get y'''[x]==-y'[x] Exp[-y[x]]==-y'[x] y''[x].

Mathematica can handle this "equivalent" ode and evaluates a unique solution

Y = DSolveValue[{y'''[x] == -y'[x] y''[x],y[0]==0}, y, x]
(*Function[{x}, 2 Log[Cosh[(x Sqrt[C[1]])/Sqrt[2]]]]*)


The solution depends on one parameter C[1]. C[1] is choosen to fullfill the boundary condition

 Y''[0] == 1 (*Y''[0] ==Exp[-0]*)
(* C[1]==1*)
Y/. %
(*Function[{x}, 2 Log[Cosh[(x Sqrt[1])/Sqrt[2]]]]*)


As you can see no additional boundary condition can be required! This solution has slope Y'[0]==0

I assume because you are under-specifying the conditions, MMa cannot solve for two unknowns with only one equation. Are you sure that your choices of C[1] and C[2] give a unique solution to the problem. There are some instances where MMa can satisfy one condition by solving for one of the constants and leave the other unevaluated, but evidently not in this case. MMa finds a solution if you specify two conditions such as

DSolve[{y''[x] == -2 Exp[-y[x]], y[0] == 0, y'[0] == 0}, y[x],
x] // FullSimplify

{{y(x)->log(cos^2(x))},{y(x)->log(cos^2(x))},{y(x)->log(cos^2(x))}}*)


There are inverse function warnings, but we get a solution.

• it is certainly not unique. I thought Mathematica could output a solution with only one free constant C[1]... I guess I had overestimated DSolve... – user58955 Feb 3 '19 at 15:23
• It really is the fact that you can't solve for two unknowns with one equation whether DSolve is trying or not. For this case if you look at your solution with no conditions, you will see that there is no way to make y[0]==0 by assigning only one of the constants. I have seen DSolve do exactly what you are trying to do on other deq's when it made sense. – Bill Watts Feb 3 '19 at 18:42
• y[0]==0 imposes a condition between C[1] and C[2]. I thought DSolve could solve that condition, plug it back into the general solution to kill one of the constants – user58955 Feb 4 '19 at 7:04
• That is one big ask, especially since it has no idea which constant you would like to keep. – Bill Watts Feb 4 '19 at 7:33