Fixed Point Iteration

Andy Long, 2/16/15
Thanks to: 
1. http://www.math.missouri.edu/~stephen/num-methods/2.2.iterate.nb
2. http://mathworld.wolfram.com/notebooks/DynamicalSystems/LogisticMap.nb

Here we are going to illustrate fixed point iteration using mathematica.  Let us set up a function

  g(x) = cos(x).  

We will work in the interval a<=x<=b, where a = 0, and b = 1.  Our starting value is (Subscript[p, 0]) = 0.5.

Clear[g,a,b,p0]

g[x_]=Cos[x];
p0=0;
a=0;
b=1;

Now let us do the iteration:

Clear[p,k]
p[0]=N[p0];
Do[p[k]=N[g[p[k-1]]],{k,1,100}]

Let’s write out the values:

TableForm[Table[{k,p[k]},{k,0,11}]]

Now let’s do a bunch of plots, and then make a movie.  What do you think the Mathematica code is doing here?

FixedPointSegments[g_,x0_,its_]:=Module[
{l=NestList[g[#]&,x0,its]},
Partition[Flatten[Transpose[{l,l}]],2,1]
];
MakeMovie[g_,p0_,a_,b_]:=
Module[{p2=Partition[FixedPointSegments[g,p0,15],2,1]},
movie=Table[Plot[{g[x],x},{x,a,b},PlotStyle->{{},Dashing[{.02}]},
Prolog->MapIndexed[{Hue[#2[[1]]/Length[p2]],Line[#]}&,Take[p2,i]],
AspectRatio->Automatic,
AxesLabel->TraditionalForm/@{(Subscript[x, n]),(Subscript[x, n+1])}
],{i,Length[p2]}];
ListAnimate[movie]
]

MakeMovie[g,p0,a,b]

Now let’s try other functions.  When does the sequence p[k] converge?

Clear[p,g,p0,a,b]
g[x_]=(1/2)+((Sin[x])/2);
p0=0;
a=0;
b=1;
p[0]=N[p0];
Do[p[k]=N[g[p[k-1]]],{k,1,100}]
TableForm[Table[{k,N[p[k]]},{k,0,11}]]

MakeMovie[g,p0,a,b]

Clear[p,g,p0,a,b,k]
g[x_]=1-(x^2);
p0=0.6;
a=0;
b=1;
p[0]=N[p0];
Do[p[k]=N[g[p[k-1]]],{k,1,100}]
TableForm[Table[{k,N[p[k]]},{k,0,11}]]

MakeMovie[g,p0,a,b]