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. >>
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}}
Reduce[h[x] == 0 && -1/2 < x < 5/4, {x}, Reals] // N
works also.
$\endgroup$
Solve/NSolve
warning msg suggested trying the domain Reals..
$\endgroup$
Commented
Mar 13, 2015 at 15:28
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.