Jacobs, Jan wrote:
> Ls,
> I need to evaluate gn =: f^:n (g0) where g0 is an gray-level image.
> f is a recurrent relation g(n+1)=f(g(n)) but needs the iteration count,
> one out of 0..n-1, for indexing in a global array.
> I managed to do this by f^:n (g0,0) and splitting the argument in an
> image and index by 'state index'=.y. and construct at the end  (f
> state);>:index but this is not elegant.
> How do I this the right way?
> Jan.
>
I don't completely understand the question, but I think you need to look
at the Vocabulary page for ^: .  You can assemble a specified number of
iterates into an array, and get all the iterates up to a fixed point:

s=:_2 0 1&p.
newton=:1 : ']- u%u d. 1'
f=:s newton

      f^:(i.10) 2  NB. first 10 iterates
2 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421 1.41421
      f^:(<10) 2   NB. first 10 iterates
2 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421 1.41421
      f^:(<_) 2    NB. iterates to fixed point
2 1.5 1.41667 1.41422 1.41421 1.41421

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to