I have the following code and output where the original function is $f(x,a) = a^2 - x^2$.
f[x_, a_] = a - x^2
ref := Nest[Function[{u, v}, f[u, v]][x, y], x, 2]
ref
(-x^2 + y)[(-x^2 + y)[x]]
I want the second iteration of this function. i.e, $f(f(x)) = a^2 - (a^2 - x^2)^2$. Why am I not getting this?
Answer
In your code, you give a 2-argument function as the first argument to Nest
, but then only one expression. From the documentation, I only see examples of Nest
being given a single argument.
Here I use a single-argument function, since that seems to match the output you want,
f[x_, a_] = a^2 - x^2;
Nest[Function[x, f[x, a]], x, 2]
(* a^2 - (a^2 - x^2)^2 *)
Comments
Post a Comment