# Why doesn't Mathematica solve $x=\cos\,x$ properly? [duplicate]

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

-

## marked as duplicate by Artes, Sjoerd C. de Vries, bobthechemist, The Toad♦Dec 30 '13 at 15:25

NSolve works when restricted to reals: NSolve[x==Cos[x],x,Reals] gives {{x -> 0.739085}}. –  Rahul Oct 22 '12 at 6:58
The "Dottie number" is not known to have an explicit closed form. –  Guess who it is. Oct 22 '12 at 7:12
Strongly related: Can Reduce really not solve for x here? –  Mr.Wizard Oct 22 '12 at 11:25

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]


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


-
Thx, I just wanted to know why Mathematica didn't know to use arccos... –  Tom Wellington Oct 22 '12 at 7:09
Of note is that Reduce[] returns a Root[] object, which can then be evaluated to arbitrary precision. –  Guess who it is. Oct 22 '12 at 7:19
@J.M. I get x == Root[{-Cos[#1] + #1 &, 0.73908513321516064165}] where the "Dottie number" has 20.6 digits of precision. How can that be accurately evaluated to arbitrary precision? (Assuming that you mean arbitrary in the general sense.) –  Mr.Wizard Oct 22 '12 at 7:31
@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 &. –  Mark McClure Oct 22 '12 at 10:32
@TomWellington This answer gives more detailed discussion of the issue mathematica.stackexchange.com/questions/4694/… –  Artes Oct 22 '12 at 10:35

Another possibility :

FixedPoint[Cos[#] &, 0.5]

(* 0.739085 *)

-
You don't need &: FixedPoint[Cos, 0.5] –  Mr.Wizard Oct 22 '12 at 7:06
@Mr.Wizard Thanks, I was aware of this but thought to make the answer easier to generalize. –  b.gatessucks Oct 22 '12 at 7:11