I am trying to create a function that returns Arnold's Cat Map of size n iterated k times. I can get something out of the Function
command, but I can't figure out how to use that output as a function.
The non-iterated version of the problem is trivial. I define my mapping function:
G[x_, y_, n_] := Mod[{{2, 1}, {1, 1}}.{x, y}, n];
I want it to work with ImageTransformation
, so I define an appropriate function for that:
CatMapStep[{x_, y_}] := G[x, y, side];
where side
is calculated somewhere earlier. Now I can call ImageTransformation (let's say I have an image kitty
):
ImageTransformation[kitty, CatMapStep]
Done. But what do I do if you want to iterate CatMap k times? Well, I can hard-code k:
CatMapFiveTimes[u_] := Nest[CatMapStep[u], u, 5];
And I discovered the `Function' command, but I can't figure out how to use it. What I would really like to do is create a function that takes k as an argument, and returns a function of u. Such is the sentiment of the following incorrect snippet:
IteratedCatMap[k_] := Function[u, Nest[CatMapStep[u], u, k]; <--- DOESN'T WORK
In my fantasy world, I would then be able to define CatMapFiveTimes by invoking the following line:
CatMapFiveTimes[u_] = IteratedCatMap[5]; <--- HYPOTHETICAL
And then using it as I would the previous definition.
How can I create this function that returns a function?
Thanks, David
PS: Note that I am using Mathematica 8, although my officemate has Mathematica 9 and she couldn't get it, either.
PPS: I am completely open to a totally different approach to this problem. Ultimately, my only goal is to use Manipulate
to let my students specify how many iterations of the cat map they want to see. I will be doing similar things for the Mandelbrot set, as well.