I know it is not wise to work with recursive functions, but I think I need one. I have two vectors (arrays: state1, state2) and would like to interpolate in between with a certain step size (array: step). For three dimensions this function works:

- Code: Select all
`def recurse(state1, state2, step):`

var1 = state1[0]

while var1 <= state2[0]:

var2 = state1[1]

while var2 <= state2[1]:

var3 = state1[2]

while var3 <= state2[2]:

print var1,var2,var3

var3 *= step[2]

var2 += step[1]

var1 += step[0]

However, I will need to use vectors up to dimension 30. Moreover, the first two dimensions are additive and the rest are multiplicative.

How could I generalize these nested loops to a flexible recursive function?

Thanks in advance,

Peter