0
$\begingroup$

This question already has an answer here:

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. >>

$\endgroup$

marked as duplicate by Artes, Dr. belisarius, Sjoerd C. de Vries, m_goldberg, Michael E2 Mar 13 '15 at 16:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2
$\begingroup$

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}
$\endgroup$
2
$\begingroup$
h[x_] = Sin[x] - x^2;

Plot[h[x], {x, -.5, 1.25}]

enter image description here

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}}

$\endgroup$
  • $\begingroup$ +1, and Reduce[h[x] == 0 && -1/2 < x < 5/4, {x}, Reals] // N works also. $\endgroup$ – user9660 Mar 13 '15 at 15:05
  • $\begingroup$ it would be might helpful if the Solve/NSolve warning msg suggested trying the domain Reals.. $\endgroup$ – george2079 Mar 13 '15 at 15:28
  • $\begingroup$ @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. $\endgroup$ – Bob Hanlon Mar 13 '15 at 17:35
  • $\begingroup$ @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. $\endgroup$ – LLlAMnYP Mar 14 '15 at 17:23
0
$\begingroup$

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.