# FixedPoint doesn't work

Do you know why it doesn't print any result?I set intial value is 0.1,

h[x_] = Sin[x];

(*Plot[{x,h[x]},{x,1,50}]*)

FixedPoint[h[#] &, 0.1];

• Let me warn you at the outset: altho $0$ is a known fixed point of $\sin$, it will take a whole long while to reach it. Gray and Glynn did some Mathematica experiments on this subject in their book. (For giggles, look at the result of Plot[Nest[Sin, x, 1*^4], {x, 0, 2 π}].) – J. M. will be back soon Oct 21 '18 at 17:47
• Thx. Actually, what I want is to get the fixed point and check if they are stable or unstable. So I think to do that, I should start with "Fixedpoint" syntax, after it works then try "FixedpointList" to print some numbers which are closed to fixed point. Sin(x)=x is one equation, the other is x^2-2=x. the fixed point of x^2-2=x, is x=2 or x=-1, I want to try 1.9,2.1 some thing like that to test if this is stable or unstable point by plotting result. But I am stuck in the first step. – Erik Johnsson Oct 21 '18 at 18:01
• I think you should use Solve instead of FixedPoint to discover the fixed points: Solve[h[x] == x, x, Reals] gives only the solution $x=0$ (but in triplicate). For the other problem, Solve[x^2 - 2 == x, x, Reals] gives your desired two fixed points. – Roman Jul 29 at 10:32
• Then, after having discovered the fixed points, you can study their stability by calculating the derivative of h: With S = Solve[h[x]==x, x, Reals] you can evaluate Abs[h'[x]] /. S and see for which points the derivative is less than 1 (stable), more than 1 (unstable), or exactly 1 (need more information). See here for an extended discussion. – Roman Jul 29 at 13:21

## 2 Answers

As Bill said by looking at

NestList[Sin[#] &, 0.1, 10000]
ListPlot[%]


you can see how slowly this converges. Let's get a more quantified idea how slow!

Every iteration we push the last value x to Sin[x]. But Sin[x] itself gets closer to x as we approach zero, so what will happen there? We can look at the taylor series expansion to get the leading term

Series[Sin[x] - x, {x, 0, 3}]


-(x^3/6)+O[x]^4

which is cubic. Ideally to get an analytic solution to an arbitrary index term in our sequence we would like the solution to that by calling

RSolve[{a[n+1]==a[n]-a[n]^3/6,a[0]==1/10},a,n]


but RSolve doesn't know how to solve that. But looking at our earlier plot, approximating this by a continuous function shouldn't be too bad, so let's try that:

DSolve[{a'[x] == -(a[x]^3/6), a[0] == 1/10}, a[x], x]


{{a[x] -> Sqrt[3]/Sqrt[300 + x]}}

Plot[Sqrt[3]/Sqrt[300 + x], {x, 0, 10000}, PlotRange -> {0, 0.1}, PlotStyle -> Orange]


Which looks almost exactly as our NestList result, nice!

So how long will it take to get to the fixed point then? When using the default $MachinePrecision it will take us Solve[Sqrt[3]/Sqrt[300 + x] ==$MachineEpsilon, x]


{{x -> 6.08472*10^31}}

iterations to get to $$MachineEpsilon$$ close to zero. My machine can do roughly 20 million Nest iterations per second so this would take approximately 10^17 years! Probably it would take a lot longer even, because $MachineEpsilon is only the smallest difference that is distinguishable from 1 that will not be rounded, but close to zero we have a lot more precision since we can use negative exponents downto $$2^{-127}$$ and then we can still go down $$2^{-23}$$ more by using denormalized numbers. So until we get to a small number near zero where the decrement -a[x]^3/6 will be rounded down to zero will essentially and practically take forever :) But by using our approximate solution we can at least see that the fixed point is zero as expected: Limit[Sqrt[3]/Sqrt[300 + x], x -> Infinity]  0 As J.M. points out, the convergence is very slow. You can see this by comparing: FixedPoint[h[#] &, 0.01, 2000]  with FixedPoint[h[#] &, 0.01, 2000000]  where the third parameter specifies a max number of iterations. If you want to find the fixed point of Sin[x]==x, it may be easiest to do it symbolically. For example: FindInstance[Sin[x] == x, x] {{x -> 0}}  gives the answer immediately. To see the iterates numerically, you can use NestList[Sin[#] &, 0.1, 1000]  but this still converges very slowly towards 0. (Thanks to J.M. for seeing that I had used the wrong function earlier.) • Thx. Actually, what I want is to get the fixed point and check if they are stable or unstable. So I think to do that, I should start with "Fixedpoint" syntax, after it works then try "FixedpointList" to print some numbers which are closed to fixed point. Sin(x)=x is one equation, the other is x^2-2=x. the fixed point of x^2-2=x, is x=2 or x=-1, I want to try 1.9,2.1 some thing like that to test if this is stable or unstable point by plotting result. But I am stuck in the first step. – Erik Johnsson Oct 21 '18 at 18:01 • Erik -- I'm not sure that the question of stability makes sense without more information. What is it that you are examining the stability of? – bill s Oct 21 '18 at 18:09 • for example, if x=1.9, if we iterate f(x)=x^2-2, how it will change, and I would like to know how to implement this by using mathmatica code. – Erik Johnsson Oct 21 '18 at 18:27 • For your polynomial f, you can see the iterates in many ways. One way is: NestList[#^2 - 2 &, 1.9, 10], analogous to the NestList above. – bill s Oct 21 '18 at 19:05 • As a slight correction: in NestList[Sin[#] - # &, 0.1, 10] you are iterating$\sin x -x$and not$\sin x\$ as in the OP. – J. M. will be back soon Oct 21 '18 at 19:14