(cos=: 2&o.) ^: (i.6) b=: 1 1 0.540302 0.857553 0.65429 0.79348 0.701369 ]y=: cos^:_ b 0.739085 y=cos y 1The example cos^:_ illustrates the fact that infinite iteration is meaningful (that is, terminates) if the process being applied converges.
f=: %: - 4: A sample function
root=: 3 : 0
m=. +/ % #
while. ~:/y.
do.
if. ~:/ * f ({.,m) y.
do. y.=. ({.,m) y.
else. y.=. ({:,m) y.
end.
end. m y.
)
b=: 1 32
root b
16
f b,root b
_3 1.65685 1.77636e_15
Exercises
| 23.1 | Use the function root to find the roots of
various functions, such as f=: 6&-@! |
| 23.2 | Experiment with the function fn=: +/\ (which produces the figurate numbers when applied repeatedly to i.n), and explain the behaviour of the function fn^:(?@3:) |