I am trying to solve the following first order differential equation: $$ g'(R)=-2 \sqrt{R^2-g(R)}+2 R$$
By direct substitution it can be verified that an obvious solution is $$g(R)=R^2$$
ode=2R-2Sqrt[R^2-g[R]]-Derivative[1][g][R]
g[R_]:=R^2
ode==0
Giving True as expected.
However, using DSolve (Mathematica 11.2 for Windows 10):
Clear[g]
DSolve[ode==0, g[R], R]//FullSimplify//Expand
we find
{{g[R]->-1+E^(2 C[1])-2 R-2 Sqrt[-E^(2 C[1]) (1+R)^2]},
{g[R]->-1+E^(2 C[1])-2 R+2 Sqrt[-E^(2 C[1]) (1+R)^2]}}
As seen, Mathematica completely missed the correct solution!
Edit 1: For more details on the mathematics aspects of the solution (and the two branches of the solution), see my post at the Mathematics stack.
Edit 2: Adding initial conditions like $g(0)=0$ or $g(1)=1$, as suggested in the comments, unfortunately doesn't help.
Edit 3: Just for future reference I add the way I found to solve the ode and recover the $R^2$ solution. To do that define a new function $y(R)$ that should be zero when $g(R)=R^2$, in the following manner
g[R_] := R^2 (1 - y[R]^2)
ode1 = ode // FullSimplify // PowerExpand // FullSimplify;
DSolve[ode1 == 0, y[R], R] // Expand
which gives
{{y[R] -> 0}, {y[R] -> 1 + C[1]/R}}
The solution $y[R] \rightarrow 0$ implies $g(R)=R^2$ as expected.
After massaging the ODE as shown above, I can get Mathematica to give the correct solution, however I still don't understand why it failed in the first place.
So, my question is, why did DSolve fail in this simple example?
C[1]
? $\endgroup$NDSolve
and I can't get it to give me theR^2
solution. Note that theDSolve
doesn't really give two solutions: it gives two expressions, which can match different initial conditions. $\endgroup$NDSolve
kind of implicitly assume that the solution is unique. $\endgroup$