# When NSolve fails due to a differential situation?

c = 1.1111;
y[x_] = x - c Sin[x]
NSolve[y[x] == 0, x]


The method has procured no result.

Successive derivatives were plotted in an attempt to fix the problem.

Plot[{y[x], y'[x], y''[0], y'''[x]}, {x, -Pi, Pi}, PlotStyle -> {Thick}, GridLines -> Automatic]


This function has a root, a small value of first derivative,and an inflection point respectively@ x=0.

Method fails due to vanishing first and third derivatives. Is it correct?

It appears Newton's iteration fails as derivative value @ x=0 is extremely small as next iteration value seeking tangents do not intersect x-axis, failing to converge to a root there. What workaround do we have here?

Is (old fashioned) Regula Falsi option available to solve this? This relates to my comments the recent thread:"How to get a solution for the following equation?"

## 3 Answers

NSolve and Reduce can solve this equation by restricting search. As can be seen by inspection: x=0 is a solution and there are two other solutions symmetric about the origin (a plot reveals and noting if r is a root then so is -r: $c \sin(-r)- (-r)= -(c\sin(r)-r)=0$.

Quiet@Reduce[y[x] == 0 && Abs@x < 1, x]


yields:

x == -0.786647 || x == 0 || x == 0.786647


or

Quiet@NSolve[y[x] == 0 && Abs@x < 1, x]


yields:

{{x -> -0.786647}, {x -> 0.}, {x -> 0.786647}}


As it can be seen in Mathematica's help,

NSolve deals primarily with linear and polynomial equations.

A more general function dealing with numerical methods is FindRoot (starting points are based on the plot you've attached to your post):

FindRoot[y[x], {x, 1}]
(*{x -> 0.7866465}*)
FindRoot[y[x], {x,-1}]
(*{x -> -0.7866465}*)


For x=0 obviously y[x]==0 as well.

By default FindRoot uses Newton's method. If the initial value is reasonable, there should be no problem with finding a solution.

In general, regarding equation solving, there are two type of functions in Mathematica:

Numerical methods based:

FindRoot (arbitrary equations)

NSolve (algebraic problems, for instance finding roots of polynomials)

Symbolical methods based:

Solve (uses the most straightforward algorithms)

Reduce (deals with equations and inequalties)

FindInstance (a more complex function, allows finding multiple solutions, only suitable for equations with no parameters)

One can also use FindInstance or with V10 NumberLinePlot:

c = 1.1111;
y[x_] = x - c Sin[x];

sol = FindInstance[y[x] == 0 && -10 < x < 10, x, Reals, 15] // Values // Flatten;


{-0.786647, 0, 0.786647}

p = Point @ Transpose[{sol, Table[0, {Length @ sol}]}];

Plot[y[x], {x, -1, 1}, Epilog -> {PointSize[0.02], Red, p}]


NumberLinePlot[{y[x] == 0},
{x, -1, 1},
AspectRatio -> 0.25,
Frame -> True,
FrameTicks -> {{None, None}, {sol, None}},
GridLines -> {sol, None},
PlotTheme -> "Detailed"]