Mathematica Asked on June 8, 2021
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$?
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 *)
Answered by Vixillator on June 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP