[Jprogramming] Recursive algorithm

Robert O'Boyle bcubed at accesswave.ca
Mon Mar 14 10:34:34 HKT 2011


Hi Forum

 

I am doing some MCMC work and have been fiddling around with different ways
to implement this in J. In my testing, I have a short program, TEST, which
adds a number to an existing one, r.

 

r =: 0

 

TEST =: 3 : 0

r=: y+r

)

 

I'd like to execute TEST many times but always using the last value of r. I
can do this by building scripts within scripts but think that there has to
be a better way. I tried 

 

(TEST"0  i.10) "0 i.5

 

to execute TEST 5 times but got

 

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

 

rather than the desired

 

  0   1   3   6  10  15  21  28  36  45

 45  46  48  51  55  60  66  73  81  90

 90  91  93  96 100 105 111 118 126 135

135 136 138 141 145 150 156 163 171 180

180 181 183 186 190 195 201 208 216 225

 

Any help would be appreciated

 

Bob

 



More information about the Programming mailing list