# How do I solve for the roots of $\sin(x) - x^2=0$? [duplicate]

I have defined h[x] := Sin[x] - x^2. When I submit Solve[h[x] == 0, x], Mathematica tells me

Solve::nsmet: This system cannot be solved with the methods available to Solve. >>

## 3 Answers

I would direct you to the tutorial, specifically Input No. 10.

To quote

There is no explicit "closed form" solution for a transcendental equation like this. You can find an approximate numerical solution using FindRoot, and giving a starting value for x.

Like so:

FindRoot[Sin[x] - x^2, {x, 1}]

{x -> 0.876726}

h[x_] = Sin[x] - x^2;

Plot[h[x], {x, -.5, 1.25}] Tell Solve or NSolve the domain to search

Solve[{h[x] == 0, -1/2 <= x <= 5/4}, x] // N


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

NSolve[{h[x] == 0, -1/2 <= x <= 5/4}, x]


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

The domain can just be Reals

Solve[h[x] == 0, x, Reals] // N


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

• +1, and Reduce[h[x] == 0 && -1/2 < x < 5/4, {x}, Reals] // N works also. – user9660 Mar 13 '15 at 15:05
• it would be might helpful if the Solve/NSolve warning msg suggested trying the domain Reals.. – george2079 Mar 13 '15 at 15:28
• @george2079 - Mma always defaults to Complexes, if you want to restrict the variable to Reals you need to include Element[x, Reals] as a constraint or more restrictively specify the domain as Reals. It is consistent with this and expects you to specify your intent. – Bob Hanlon Mar 13 '15 at 17:35
• @BobHanlon - I do have to agree with george though. Its not entirely obvious to me, why Mma throws an error when you don't specify a domain, but works just fine when you do. – LLlAMnYP Mar 14 '15 at 17:23

Since this is a rather simple function, you should approximately know about the distribution of its roots. One of them should be zero. If you don't you can use Plot to observe. For example,

Plot[-x^2 + Sin[x], {x, -0.5, 1}]


Then you can use

FindRoot[-x^2 + Sin[x] == 0, {x, 1}]
(*{x -> 0.876726}*)


to find out the other root.You can also obtain more digits by using WorkingPrecision

FindRoot[-x^2 + Sin[x] == 0, {x, 1}, WorkingPrecision -> 10]
(*{x -> 0.8767262154}*)


When Solve does not work, you can try NSolve and FindRoot. You can read more about these two functions in the Documentations.