I see lots of cases where DSolve
gives solution that has $e^{c_1}$ in the solution, where $c_1$ is the integration constant.
When solving this by hand, we normally replace $e^{c_1}$ by new constant. I always wondered why DSolve
does not do this automatically?
Here is an example
ode = 2*x + 3*y[x] + (3*x + 2*y[x])*y'[x] == 0;
sol = DSolve[ode, y[x], x]
This could be made much simpler using
sol = sol //. 4 E^C[1] -> C[1]
Both solutions are of course correct. But my question is why Mathematica does not do this simplification automatically. It seems like something that the DSolve
code could do easily using a pattern at the end, or at the moment such terms show.
Update
This is comment to the good Answer by Akku14 below. I just wanted to say that at the end, it should not make difference if one keeps the constant as $e^{c_1}$ or replace it by a new constant $c_2$. To show this, using the ode given with some i.c., this below shows that the final IVP should come out the same (too small to write in comment to the above answer, so adding it here).
Solve
$$
2x+3y+\left( 3x+2y\right) y^{\prime}=0
$$
With initial conditions
$$
y\left( 0\right) =0
$$
Mathematica gives the general solution as (Using one of the two solutions it gives)
\begin{equation}
y=\frac{1}{2}\left( -3x-\sqrt{4e^{c_{1}}+5x^{2}}\right) \tag{1}
\end{equation}
Let say we keep $e^{c_{1}}$ as is. Applying initial conditions gives the
equation to solve for $c_{1}$
$$
0=-\sqrt{4e^{c_{1}}}
$$
Actually Solve
here did not solve for $c_1$ when asked. Even for reals. But we know that the solution must be $c_{1}=-\infty$. This is a valid constant of integration.
Substituting this into (1) gives the IVP solution as \begin{align} y & =\frac{1}{2}\left( -3x-\sqrt{4e^{-\infty}+5x^{2}}\right) \nonumber\\ & =\frac{1}{2}\left( -3x-\sqrt{5x^{2}}\right) \tag{2} \end{align} Now lets say we replaced $e^{c_{1}}$ by new constant, say $c_{2}$ before solving for the constant, which is what we would do when solving this by hand. So (1) now becomes \begin{equation} y=\frac{1}{2}\left( -3x-\sqrt{4c_{2}+5x^{2}}\right) \tag{3} \end{equation} Now applying initial conditions to (3) gives $$ 0=-\sqrt{4c_{2}} $$ This has the solution $c_{2}=0$. Substituting this in (3) gives \begin{equation} y=\frac{1}{2}\left( -3x-\sqrt{5x^{2}}\right) \tag{4} \end{equation} We see that (4) and (2) are the same IVP solution. So the only difference is the value of the constant of integration found, but this should not affect the final IVP solution.
Actually, when keeping the constant as Mathematica shows it, which is $e^{c_1}$ and solving the ODE with with these initial conditions, it gives warning:
Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
But it also did give the above IVP solution at the end. But with the above warning.
But if Mathematica had changed $e^{c_1}$ to $c_1$ and only after that solved for the constant of integration, then such a warning would not even show up.
May be this is another good reason for this change in how it writes the solution?
f[C[1]] -> C[1]
to any functionf
. I will add that4 E^C[1] -> C[1]
is not as safe asC[1] -> Log[C[1]/4]
(e.g., shouldC[1]
happen to appear in two places in different expressions). $\endgroup$Simplify[sol, TransformationFunctions -> {Automatic, # /. c_C :> Log[c] &, # /. Cases[#, a_?NumericQ c_C :> (c :> c/a), Infinity] &, # /. Cases[#, a_?NumericQ + c_C :> (c :> c - a), Infinity] &}]
. It works onDSolve[x y''[x] == y'[x] y[x], y[x], x]
, too. $\endgroup$