0
$\begingroup$

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$
0

3 Answers 3

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