# Iterating of piecewise function

I have this piecewise function $$f(x)=\begin{cases} x(1.5-0.5x) \quad\text{if x\le0.5},\\ x(0.5+0.5x) \quad\text{if x>0.5}. \end{cases}$$ How can I calculate iterated functions for it?

• f[x_]:=Piecewise[{{x(1.5-0.5x),x<=0.5},{x(0.5+0.5x),x>0.5}}]; {f[2],f[f[2]],f[f[f[2]]]} returns {3.,6.,21.}. And {Nest[f,2,1],Nest[f,2,2],Nest[f,2,3]} returns the same. – Bill May 20 at 5:44
• @Bill that's what NestList is for: NestList[f, 2, 3] – Roman May 20 at 7:28

Most likely the three built-in iteration function that will be interest to you are FixPoint, Nest and NestList.

FixPoint and Nest both return only the final iterate. NestList returns a list of the initial value plus all the iterates. FixPoint and Nest are very similar, except FixPoint checks for converges and stops if it finds it. Nest makes no such check and will always perform the full iteration.

These function don't care whether the function they are iterating is piecewise or not.

Examples

f[x_] := Piecewise[{{x (1.5 - 0.5 x), x <= 0.5}, {x (0.5 + 0.5 x), x > 0.5}}]
FixedPoint[f, 3/4, 500] // N


0.506723

Nest[f, 3/4, 500] // N


0.506723

NestList[f, .75, 10]


{0.75, 0.65625, 0.543457, 0.419401, 0.541153, 0.417, 0.538556, 0.414299, 0.535626, 0.411261, 0.532324}