Is this solution to nonlinear first order ODE correct?
The explicit solution given by DSolve
is actually Solve
d from the implicit solution. This can be verified by:
Trace[DSolve[eqn, y, x], Solve[_, y[x]], TraceInternal -> True] // Flatten
(* {HoldForm[Solve[-2 Sqrt[1 - y[x]] == Sqrt[x] + C[1], y[x]]]} *)
% // ReleaseHold
(* {{{y[x] -> 1/4 (4 - x - 2 Sqrt[x] C[1] - C[1]^2)}}} *)
So the question boils down to "why doesn't Solve
give the condition for the solution", and this has been explained in Possible Issues of document of Solve
:
Solve
gives generic solutions; solutions involving equations on parameters are not given… WithMaxExtraConditions -> All
,Solve
also gives non-generic solutions.
Solve[-2 Sqrt[1 - y[x]] == Sqrt[x] + C[1], y[x], MaxExtraConditions -> All]
(* Alternatively: *)
Solve[-2 Sqrt[1 - y[x]] == Sqrt[x] + C[1], y[x], Method -> Reduce]
(* {{y[x] -> ConditionalExpression[1/4 (4 - x - 2 Sqrt[x] C[1] - C[1]^2),
Sqrt[x] + C[1] + Sqrt[(Sqrt[x] + C[1])^2] == 0]}} *)
Picking up from my earlier comment, note that you first have to define a branch for square-root(positive/negative). The conventional branch is positive. Once that is agreed upon, eyeball the implicit solution in the following form:
$$-4\sqrt{1-y}=2\sqrt{x}+2C_1$$
The LHS is non-positive, and so should be the RHS. This information gets lost when one squares both sides to get the explicit solution.
This means that $\sqrt{x}+C_1 \leq 0\; \forall C_1\; \forall (x,y)$ satisfying the above equation.
Note that here $C_1=-\frac{C}{2}$ as you mentioned in the implicit solution in the question.
What we learn here is, always try to verify solutions. You might get conditons for variables and parameters.
test = (eqn /. First@sol) // Simplify
red = test // Reduce[#, Reals] &
(* (C[1] < 0 && 0 <= x <= C[1]^2) || (C[1] == 0 && x == 0) *)
RegionPlot[red /. C[1] -> a, {x, -2, 5}, {a, -6, 6},
FrameLabel -> {x, "C[1]"}]