(I would be glad to accomplish the following in either Python or MATLAB/Octave. Below I outlined the problem in Python.)
I would like to define a 17x8 array of functions via a recurrence
if 0<k<16:
f[k,n+1](j) = A(k,j)*f[k-1,n](j) + B(k,j)*f[k+1,n](j)
elif k==0:
f[k,n+1](j) = B(k,j)*f[k+1,n](j)
elif k==16:
f[k,n+1](j) = A(k,j)*f[k-1,n](j)
The functions A(k,j)
and B(k,j)
are not indexed, they do not need an array. They are not essential to this problem. The initial values for the recurrence are given by the known values
if k==8:
f[k,0](j)=0
else:
f[k,0](j)=1
which hold for arbitrary j
.
How can I define an array of functions recurrently in a 2D array? I have seen examples such as this that construct an array of functions by
myFuncs = [f0,f1,f2]
myFuncs[2](...) #calls f2
However, this requires me to create and name individual functions before lumping them together in the myFuncs
array. In contrast, I need to build this table up without naming all 136 functions in the 17x8 array. How can I accomplish this?
EDIT: To be explicit and demonstrate that it is possible to write the solution as a function of k, the recurrence I am trying to solve is
f[k,n+1](j) = sqrt(j+k-8)*f[k-1,n](j) + sqrt(k+j-7)*f[k+1,n](j)
Using the known values for n=0
I can obtain the following for n=1:
f[9,1](j) = sqrt(j+1)
f[7,1](j) = sqrt(j)
with the others equal to zero, and then for n=2
f[10,2](j) = sqrt((j+1)*(j+2))
f[8,2](j) = 2*j+1
f[6,2](j) = sqrt(j*(j-1))
with the others zero. Doing this by hand is prone to errors, however, and I would like to generalize this because there are two other recurrences I wish to calculate all these functions for.