Mathematica V 12.2 on windows 10. I was using Mathematica to check my solution for this ODE. Mathematica gives 2 solutions. Any idea where the second solution came from? and is it correct?
Here is my solution, and Mathematica's solution
ClearAll[y, x];
ode = y'[x] == 2*Sqrt[1 + y[x]]*Cos[x];
sol = DSolve[{ode, {y[Pi] == 0}}, y, x]
(* {{y->Function[{x},-2 Sin[x]+Sin[x]^2]},{y->Function[{x},2 Sin[x]+Sin[x]^2]}} *)
Only the second solution verifies. And that is what I obtained also. The question is, how did Mathematica obtain the first one above?
Assuming[Element[x, Reals], Simplify@(ode /. sol[[1]])]
(* Cos[x] Sin[x] == Cos[x] *)
Assuming[Element[x, Reals], Simplify@(ode /. sol[[2]])]
(* True *)
My solution:
The ODE
$$
\frac{ \mathop{\mathrm{d}y}}{\mathop{\mathrm{d}x}} = 2 \sqrt{y +1}\, \cos \left(x \right)
$$
is separable. Hence
\begin{align*}
\left(\frac{1}{2 \sqrt{y +1}}\right)\mathop{\mathrm{d}y}&= \cos \left(x \right)\mathop{\mathrm{d}x}\\
\int \left(\frac{1}{2 \sqrt{y +1}}\right)\mathop{\mathrm{d}y}&= \int \cos \left(x \right)\mathop{\mathrm{d}x}\\
\sqrt{y +1} &= c_{1}+\sin \left(x \right)
\end{align*}
Initial conditions are now used to solve for $c_{1}$. Substituting $x=\pi$ and $y=0$ in
the above solution gives an equation to solve for the constant of integration.
\begin{align*}
\sqrt{1} &= c_{1}
\end{align*}
But $\sqrt{1}=1$, taking the principal root. Therefore
\begin{align*}
c_1 &= 1
\end{align*}
Substituting $c_{1}$ found above in the general solution gives
$$
\sqrt{y \left(x \right)+1} = \sin \left(x \right)+1
$$
Solving for $y \left(x \right)$ gives
\begin{align*}
y(x)+1 &= (1+\sin(x))^2 \\
y(x)+1 &= (1+\sin^2(x)+2 \sin(x)) \\
y(x) &= \sin^{2}x +2 \sin(x)
\end{align*}
From the above, I see that Mathematica must have obtained two solutions for $c_1$ as $\pm 1$ when taking $\sqrt 1$.
Only then will it obtain these two solutions. For when $c_1 = -1$, the first solution that it shows will come out. And when $c_1= 1$, the second solution will come out.
Is Mathematica's first solution correct? Should Mathematica have obtained only that $c_1 = 1$ and not $c_1 = \pm 1$?
y'[x]^2 == (2*Sqrt[1 + y[x]]*Cos[x])^2
. This seems to happen "a lot," enough that I'm not surprised. I'm not sure why it doesn't check, other than in some cases the checking might take a long time. $\endgroup$DSolve
follows your path up to the point where you apply the initial conditions.DSolve
first solves fory[x]
, squaring both sides and creating a quadratic equation forC[1]
. $\endgroup$