9
$\begingroup$

I have this equation $$x^2 \left(\sqrt{1-y^2} \sin (x)-\sin (4 x)\right)+2 x y=0$$ I want to solve this equation and find $y$ in terms of $x$. I use Solve

Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y == 0, y]

and I obtain two solutions

y -> (-Sqrt[2] Sqrt[
   8 x^2 Sin[x]^2 - x^4 Cos[2 x] Sin[x]^2 + x^4 Cos[8 x] Sin[x]^2] + 
  4 x Sin[4 x])/(2 (4 + x^2 Sin[x]^2))

and

y -> (Sqrt[2] Sqrt[
   8 x^2 Sin[x]^2 - x^4 Cos[2 x] Sin[x]^2 + x^4 Cos[8 x] Sin[x]^2] + 
  4 x Sin[4 x])/(2 (4 + x^2 Sin[x]^2))

Then, when I substitute these solutions in the original equation, they are not verified. Can someone please guide me where I am going wrong?

$\endgroup$

3 Answers 3

8
$\begingroup$

Solve yields a generic result, while Reduce provides complete description of the solution space. With the MaxExtraConditions -> All option in Solve one can get in various cases as much as Reduce can provide however this isn't always possible.
The fact that Solve provides a generic result sometimes apears to be convenient as is the case here, however that generic solution need not always to be an actual solution. More extensive discussion one can find in What is the difference between Reduce and Solve?

For an insight what kind of solution one might expect here we can sketch them with

ContourPlot[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0, 
             {x, -10, 10}, {y, -2, 2},
             ContourStyle -> Thick, AspectRatio -> Automatic, ImageSize -> 600, 
              PlotPoints -> 90, MaxRecursion -> 3]

enter image description here

It is obvious thet there are solutions with -1 <= y <= 1 only. We can see that for certain real ranges of x thare is no solution, for others on can find one or two solutions. As we mentioned above Reduce is more powerful, nonetheless we can find solutions with Solve as well:

Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4x]) x^2 + 2 x y == 0 && -5 < x < 5, y, Reals]

enter image description here

Let's demonstrate that the "generic sollution" need not be an actual solution.

sol = Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y == 0, y];
ex1 = (((Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y)/. sol[[1]] // Simplify);
Plot[ ex1, {x, -5, 5}, PlotStyle -> Thick, WorkingPrecision -> 30]

enter image description here

y is a solution only when ex1 vanishes. Since it is hard demonstraiting with symbolic functionality we can reach satisfactory insight with plotting of the graph of ex1. One can easily observe that ex1 is not a solution e.g. for 3.5 < x < 4. Similar analysis for another "generic solution" ensures that we can get a specific solution only for appropriate ranges and simplifying the equation with a generic solution cannot yield zero in general. One can see how many different cases can be found with Reduce e.g.

Reduce[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0 && -10 < x < 10, y, Reals]

This output is very large and one realizes why there the system suppresses the output when no reasonable restriction for x is provided.

$\endgroup$
4
  • 1
    $\begingroup$ Beat me to it! +1. $\endgroup$
    – ciao
    Commented Aug 23, 2020 at 3:25
  • $\begingroup$ @Artes I really appreciate your time and answer. $\endgroup$
    – user73597
    Commented Aug 23, 2020 at 9:40
  • $\begingroup$ @Artes Another problem. It seems that ContourPlot does not consider double roots of an equation. So, one should not only consider its solutions. $\endgroup$
    – user73597
    Commented Aug 23, 2020 at 9:58
  • 1
    $\begingroup$ @Mariya You are welcome. ContourPlot simply generates lines in the plane {x, y} where this equation (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0 is satisfied. It doesn't have anything to do with multiple roots. Nevertheless it appears to be helpful when analyzing possible solutions. There is an extensive discusion in the post I linked in the answer If you are not familiar with subtleties regarding symbolic equation solving functionality. $\endgroup$
    – Artes
    Commented Aug 23, 2020 at 13:00
2
$\begingroup$

I don't think you are doing anything wrong, but the result is interesting. When you plug in numbers, you get the equation satisfied only sometimes.

eq[x_, y_] = (Sqrt[1 - y^2]*Sin[x] - Sin[4*x])*x^2 + 2*x*y

let Mathematica solve it.

sol = Solve[eq[x, y] == 0, y] // Flatten // Simplify

and look at some values. A few x,y values for the first solution:

tab1 = Table[{x, y /. sol[[1]]}, {x, 0, 5, .2}] // N

plug the values into the original equation:

result1 = Table[{tab1[[i, 1]], eq[tab1[[i, 1]], tab1[[i, 2]]]}, {i, 1, Length[tab1]}];

Looking at the result the equation is satisfied to machine precision up to about $x=2.4$ and for higher values, only occasionally. If you look at the second solution the same way, the lower values are wrong, while the higher values are right about half the time.

So I understand why Mathematica does not verify the solutions, but I do not understand why we are getting these answers in the first place.

As a check, M12 and M8 produce the same results, except for minor simplification differences.

$\endgroup$
1
  • $\begingroup$ Thanks. You are right. It seems that Mathematica square the equation to find $y$, and in this way, it produces the extraneous solutions. $\endgroup$
    – user73597
    Commented Aug 22, 2020 at 22:55
2
$\begingroup$

I cannot find an error in what you write but the issue lies with Solve which does not quite "solve" equations. Mathematica indeed finds two solutions:

e[x_, y_] := x^2 (Sqrt[1 - y^2]*Sin[x] - Sin[4*x]) + 2 x y;
sol = Solve[e[x, y] == 0, y];
TableForm[%]
f[x_] := e[x, y] /. First[sol];
g[x_] := e[x, y] /. Last[sol];

enter image description here

Neither solution can be reduced to 0 by Simplify or FullSimplify. Plotting may help; each solution may be OK in part of the domain for $x$ but not everywhere as shown here:

Plot[{f[x], g[x]}, {x, 0, 10}, PlotRange -> All]

enter image description here

However the documentation for Solve mentions that

Solve does not eliminate solutions that are neither generically correct nor generically incorrect

Have a look at @Artes ' comment for a link to a discussion.

$\endgroup$
5
  • 1
    $\begingroup$ Thanks. It seems that Mathematica square the equation to find $y$, and in this way, it produces the extraneous solutions. $\endgroup$
    – user73597
    Commented Aug 22, 2020 at 22:56
  • $\begingroup$ @Mariya Please report at [email protected] $\endgroup$
    – Alan
    Commented Aug 22, 2020 at 23:42
  • $\begingroup$ @A.G. For what? $\endgroup$
    – user73597
    Commented Aug 22, 2020 at 23:45
  • 1
    $\begingroup$ This is not a bug. For a detailed discussion of various restrictions see What is the difference between Reduce and Solve?. Solve yields a genric solution and in certain ranges of x such a generic solution need not be a solution. $\endgroup$
    – Artes
    Commented Aug 23, 2020 at 0:18
  • $\begingroup$ For the first plot, specify a WorkingPrecision so that arbitrary-precision is used rather than machine precision. $\endgroup$
    – Bob Hanlon
    Commented Aug 23, 2020 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.