# Why is DSolve unable to solve this second order ode with initial conditions? Any workaround?

Fyi, report to WRI as suggedted. [CASE:4956902]

This ode is similar to one here but for some reason DSolve could not able to solve this. This ode is from a textbook

My question is: What is the reason it can't solve this since it is similar to the one in the above link, and any workaround to make DSolve solve this one?

I solved by hand below as well. I used the Trace commands by Michael E2 from the above answer, but it did not help me figure where it went wrong and I am not good at internal tracing of Mathematica functions.

## Code

ClearAll[y, x];
ode = y''[x] == y'[x]*Exp[y[x]];
ic = {y == 0, y' == 1};
DSolve[{ode, ic}, y[x], x]
(* {} *)


The solution it should have given is y[x]->-Log[4-x] as shown below.

## Verification of solution

mysol = y -> Function[{x}, -Log[4 - x]]
ode /. mysol ic/.mysol ## Hand solution

\begin{align*} y^{\prime\prime} & =y^{\prime}e^{y}\\ y\left( 3\right) & =0\\ y^{\prime}\left( 3\right) & =1 \end{align*} Let $$p=y^{\prime}$$, then $$y^{\prime\prime}=\frac{dp}{dx}=\frac{dp}{dy}\frac{dy}{dx}=\frac{dp}{dy}p$$. The ode becomes \begin{align*} \frac{dp}{dy}p & =pe^{y}\\ \frac{dp}{dy} & =e^{y} \end{align*} Which has the solution $$\begin{equation} p=e^{y}+c_{1}\tag{1}% \end{equation}$$ Using initial conditions given by $$p\left( 3\right) =1,y\left( 3\right) =0$$ the above becomes $$1=1+c_{1}$$ Hence $$c_{1}=0$$ and the solution (1) simplifies to \begin{align*} p & =e^{y}\\ \frac{dy}{dx} & =e^{y} \end{align*} This is separable. $$e^{-y}dy=dx$$ Integrating gives $$\begin{equation} -e^{-y}=x+c_{2}\tag{2} \end{equation}$$ But $$y\left( 3\right) =0$$, hence $$-1=3+c_{2}$$ Therefore $$c_{2}=-4$$ and (2) becomes \begin{align*} -e^{-y} & =x-4\\ e^{-y} & =4-x\\ -y & =\ln\left( 4-x\right) \\ y & =-\ln\left( 4-x\right) \end{align*}

## Attempt at Tracing using Michael E2's code

ClearAll[y,x];
ode=y''[x]==y'[x]*Exp[y[x]];
ic={y==0,y'==1};
Trace[DSolve[{ode,ic},y[x],x],s_Solve:>HoldForm[s]->s,TraceInternal->True]//Flatten//Column • Only workaround: ode = y''[x] == y'[x]*Exp[y[x]]; ic = {y == 0, y' == A}; sol = DSolve[{ode, ic}, y[x], x]; Limit[y[x] /. First@sol, A -> 1]. Jul 30, 2022 at 11:05
• Thanks for all the great answers, I wish I can accept both of them. Report to WRI. Jul 31, 2022 at 21:26

I'd report this to WRI. If buried in the DSolve code base is a way to solve this, then the decision tree misses it. Otherwise, they should implement a way. DSolve has a method to solve y''[x] == F[y[x]]. Here's is a modification of it to solve y''[x] == F[y[x], y'[x]] (tested only on this problem!).

I snatched the code for y''[x] == F[y[x]] and modified by hand. The modifications are surround by (**) on either side.

mySpecialOrder2BVP // ClearAll;
First@DownValues@DSolveDSolveExtendedLibraryDumpSpecialOrder2BVP /.
s_Symbol :>
With[{v = Symbol@SymbolName[s]},
RuleCondition[v, ! MemberQ[Context[s], \$ContextPath]]] /.
SpecialOrder2BVP -> mySpecialOrder2BVP


Edit the output above to be the following:

(*"
* Solves y''[x] == F[y[x], y'[x]] if LHS is integrable w.r.t x
"*)
DownValues@mySpecialOrder2BVP = {
HoldPattern[
mySpecialOrder2BVP[eqn_, ycond_, yprimecond_, a_, y_, x_]] :>
Block[{rhs, w, res1, c, res},
rhs = eqn[] /.  (**) {y[x] | y'[x] -> w}(**);
(res1 =
Quiet[Solve[ (**)
Derivative[y][x] == Integrate[eqn[], x](**)  + c /.
x -> a /. {ycond, yprimecond}, c]];
(res1 = (**)
Derivative[y][x] ==
Integrate[eqn[], x](**)  + (c /. res1[]);
res = (**)
DSolve[res1 && ycond[] == ycond[], {y}, {x}]; (**)
res /; FreeQ[res, (**)DSolve(**)]) /;
MatchQ[res1, {{c -> m_}}] && FreeQ[res1, Integrate]) /;
FreeQ[rhs, y | x]]
};

mySpecialOrder2BVP[ode, Sequence @@ First@Solve[ic], 3, y, x]

(*  {{y -> Function[{x}, -Log[4 - x]]}}  *)


I don't have a way to hook this into DSolve automatically.

Edit notice: I neglected to mark the change from the internal DSolveDSolveParser to DSolve. DSolveParser[] threw a couple of Part::partw errors that could be ignored. Calling the top-level DSolve seemed the best fix for this answer. The Condition should therefore be FreeQ[res, DSolve]. It seems to me that the errors are but that arise because the internal SpecialOrder2BVP[] hasn't been updated to pass DSolveParser[] complete option value data (with the new options like IncludeSingularSolutions). I haven't noticed anyone reporting such a bug yet, though. (Also, I don't know why Integrate is called twice. It seems wasteful.)

• Great response (+1)! May I suggest that you report this issue to WRI, because you have a better understanding of the matter than I or (I surmise) the OP. Thanks. Jul 31, 2022 at 16:35
• @bbgodfrey Thanks! I reported it, with reference to Nasser's case number and my further observations about Part::partw and Integrate. My case number: [CASE:4957084]. Aug 1, 2022 at 16:03

With a bit of assistance, DSolve can obtain the desired solution. ode has a first integral, which is obtained by

Integrate[Subtract @@ ode, x, GeneratedParameters -> C] == 0
(* -E^y[x] + C + Derivative[y][x] == 0 *)


Applying the initial conditions then yields

Solve[% /. x -> 3 /. Rule @@@ ic, C] // Flatten
(* {C -> 0} *)


DSolve now obtains the desired solution

DSolve[{%% /. %, ic}, y[x], x] // Flatten
(* {y[x] -> -Log[4 - x]} *)


To answer why DSolve fails in the question, consider

s = DSolveValue[{ode, First@ic}, y[x], x, , Assumptions -> C ∈ Reals]
(* -Log[-(1/C) + (E^(3 C - x C) (1 + C))/C] *)


Applying the second boundary condition then yields

Solve[1 == D[s, x] /. x -> 3, C] // Flatten
{C -> 0}


Of course, inserting this value of C into s fails.

Power::infy: Infinite expression 1/0 encountered.

On the other hand, as suggested by Mariusz Iwaniuk in a comment,

Limit[s, %]
(* -Log[4 - x] *)


does work. Apparently, DSolve` does not try this.