3
$\begingroup$

Why doesn't Mathematica solve x == Cos[x] properly?

Both Solve and NSolve fail with the message:

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

$\endgroup$
3
  • 4
    $\begingroup$ NSolve works when restricted to reals: NSolve[x==Cos[x],x,Reals] gives {{x -> 0.739085}}. $\endgroup$ Commented Oct 22, 2012 at 6:58
  • 3
    $\begingroup$ The "Dottie number" is not known to have an explicit closed form. $\endgroup$ Commented Oct 22, 2012 at 7:12
  • 2
    $\begingroup$ Strongly related: Can Reduce really not solve for x here? $\endgroup$ Commented Oct 22, 2012 at 11:25

2 Answers 2

8
$\begingroup$

In this case you might use:

InverseFunction[Cos] 
ArcCos 

One can see that this is valid only over the interval (-1, 1) which is probably why Solve does not give an answer:

Plot[{Cos@x, ArcCos@x}, {x, -Pi, Pi}, PlotStyle -> Thick] 

Mathematica graphics

A few methods to find the intersection in the illustration:

N @ FindInstance[x == Cos[x], x] N @ Reduce[{x == Cos[x], -1 < x < 1}, x] FindRoot[x == Cos[x], {x, 0}] 
{{x -> 0.739085}} x == 0.739085 {x -> 0.739085} 

I would be remiss not to point out that my plot above is only looking at real values. One can see that as implemented ArcCos does handle the full circle:

Plot[{Cos @ ArcCos @ x, x + 1}, {x, -20, 20}] 

Mathematica graphics

$\endgroup$
7
  • $\begingroup$ Thx, I just wanted to know why Mathematica didn't know to use arccos... $\endgroup$ Commented Oct 22, 2012 at 7:09
  • $\begingroup$ Of note is that Reduce[] returns a Root[] object, which can then be evaluated to arbitrary precision. $\endgroup$ Commented Oct 22, 2012 at 7:19
  • 1
    $\begingroup$ @Mr.Wizard The 0.739... in the argument is not used to compute the value of the root, only to isolate it from any other potential roots. In this sense, it is similar to the index for normal polynomial Root objects, as returned by say, Solve[x^5 -x-1 == 0, x]. Of course, the root can be computed to arbitrary precision using the -Cos[#1] + #1 &. $\endgroup$ Commented Oct 22, 2012 at 10:32
  • 1
    $\begingroup$ @TomWellington This answer gives more detailed discussion of the issue mathematica.stackexchange.com/questions/4694/… $\endgroup$ Commented Oct 22, 2012 at 10:35
  • 1
    $\begingroup$ As @Mark says, you can treat the 0.739... as a "proximity indicator"; you can thus read Root[{-Cos[#1] + #1 &, 0.73908513321516064165}] as "the root of the equation $x-\cos\,x=0$ in the vicinity of $0.739085\dots$". You can apply something like N[#, 100] & to it, and the internal algorithms will then compute the root to higher precision. $\endgroup$ Commented Oct 22, 2012 at 11:11
6
$\begingroup$

Another possibility :

FixedPoint[Cos[#] &, 0.5] (* 0.739085 *) 
$\endgroup$
2
  • 3
    $\begingroup$ You don't need &: FixedPoint[Cos, 0.5] $\endgroup$ Commented Oct 22, 2012 at 7:06
  • 1
    $\begingroup$ @Mr.Wizard Thanks, I was aware of this but thought to make the answer easier to generalize. $\endgroup$ Commented Oct 22, 2012 at 7:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.