notSink.nb

Based on iteratedMap1D.nb  (1-dimensional)
version 1.5 (2021-03-03) Variables a, x, etc. are made local in the runIteratedMap function.

This shows examples of fixed points of the map g that are not sinks by my definition.

runIteratedMap := Module[{cobwebDiagram, a, x, xm, newx, iterates, initialPoint},
nList = Range[0, nIterations];
x = x0;
Do[x = g[x], {nTransients}];
If[nTransients > 0, Print["Initial point = ", x0, ". Start plotting after ", nTransients, " iterates at x = ", x] ];
initialPoint = Point[{x,x}];
path = {{x, x}};
iterates = {x};  (* this will give the seqence of iterates *)
Do[
newx = g[x];
iterates = AppendTo[iterates, newx];
path = Join[path, {{x, newx}, {newx, newx}}];
x = newx,
{nIterations}  (*Do it this many times *)
];
cobwebDiagram = Plot[{g[x], x}, {x, xMin, xMax}, AspectRatio -> Automatic (* y = x is 45° degree line *), PlotStyle ->{Automatic, Dotted}, Epilog -> {PointSize[Large],initialPoint,Line[path]}
];
Print@TableForm[{nList, iterates}, TableHeadings-> {{"n", "x_n"}, None}];
Show[cobwebDiagram]
];

g[x_] := Which[x <= 0, x/2, x < 1, 2x, True, -x/2];
x0 = 1.5;
xMin = -1.1;
xMax =2.1;
nTransients = 0;
nIterations =30;
(* Define parameters before running Module *)
runIteratedMap

g[x_] := N[x + ((Sin[ x])^2)];
x0 = -3;
xMin = -3.2;
xMax =3.2;
nTransients = 0;
nIterations =30;
(* Define parameters before running Module *)
runIteratedMap