4
$\begingroup$

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$?

$\endgroup$
5
  • 4
    $\begingroup$ No, but it is a solution to the rationalized ODE, 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$ – Michael E2 Dec 25 '20 at 14:31
  • 1
    $\begingroup$ DSolve follows your path up to the point where you apply the initial conditions. DSolve first solves for y[x], squaring both sides and creating a quadratic equation for C[1]. $\endgroup$ – Michael E2 Dec 25 '20 at 15:33
  • $\begingroup$ I came across a similar issue some time ago, see here: mathematica.stackexchange.com/questions/214195/… $\endgroup$ – Hans Olo Dec 25 '20 at 18:27
  • $\begingroup$ Maple produces the only solution $y\! \left(x\right)=\sin\! \left(x\right)^{2}+2 \sin\! \left(x\right)$ in according with that theorem . $\endgroup$ – user64494 May 26 at 6:10
  • $\begingroup$ The bug still occurs in 12.3. $\endgroup$ – user64494 May 26 at 6:18
2
$\begingroup$
ClearAll[y, x, ode, sol];

(* The given equation ode is a non-linear (quadratic) ODE, which yields two 
   solutions, as expected. Since both solutions satisfy the ODE they are both correct.
   Note that the ODE is equivalent to: y'[x]^2 == 4*(1 + y[x])*Cos[x]^2 *)

ode = y'[x] == 2*Sqrt[1 + y[x]]*Cos[x];
sol = DSolve[{ode, {y[Pi] == 0}}, y[x], x]

(* OUT: {{y[x] -> -2 Sin[x] + Sin[x]^2}, {y[x] -> 2 Sin[x] + Sin[x]^2}} *)

(* In order to obtain a single solution, we need to reduce the ODE to
a quasi-linear ODE, by defining an auxiliary boundary condition, say
at x=0, that will constrain the solution to the one that we seek *)

bcNew = ode /. x -> 0

(* OUT: y'[0] == 2 Sqrt[1 + y[0]] *)

solNew = DSolve[{ode, y[Pi] == 0 && bcNew}, y[x], x]

(* OUT: {{y[x] -> 2 Sin[x] + Sin[x]^2}} *)

(* QED *)
$\endgroup$
2
  • $\begingroup$ Your claim " Note that the ODE is equivalent to: y'[x]^2 == 4*(1 + y[x])*Cos[x]^2 *) " does not correspond to reality. $\endgroup$ – user64494 May 26 at 7:17
  • $\begingroup$ +1 for your workaround. $\endgroup$ – user64494 May 26 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.