A Recursive Function Problem in Mathematica
Hello,
I have the following recursive function:
![\beta_{kj}=\sum_{l=k-N+1}^k \frac{\beta_{l(j-1)}}{(k-l)!} I_{[0,(j-1)(N-1)]}(l)](http://latex.codecogs.com/png.latex?\beta_{kj}=\sum_{l=k-N+1}^k \frac{\beta_{l(j-1)}}{(k-l)!} I_{[0,(j-1)(N-1)]}(l))
where 
![I_{[a,b]}(l)=<br />
\left\{<br />
\begin{array}{cc}<br />
1 & a \leq l \leq b\\<br />
0 & \mbox{ otherwise}<br />
\end{array}<br />
\right.](http://latex.codecogs.com/png.latex?I_{[a,b]}(l)=<br />
\left\{<br />
\begin{array}{cc}<br />
1 & a \leq l \leq b\\<br />
0 & \mbox{ otherwise}<br />
\end{array}<br />
\right.)
and I tried to write it using Mathematica as following:
Code:
fun[m_,n_,r_]:=If [m<=r<=n,1,0];
B[0,j_,N_]:=1;
B[1,j_,N_]:=j;
B[k_,1,N_]:=1/k!;
B[k_,j_,N_]:=Sum[B[l,j-1,N]/Factorial[k-l]×fun[0,((j-1)×(N-1)),l],{l,l=k-N+1,k}]
I have this function programmed well in MATLAB, and I use it as a reference to check the Mathematica code which fails to give correct answers. Can anyone tell me where is the error in the Mathematica code?
Hint: If you write at Mathematica B[3,3,3] it must give you 4, B[2,3,3] = 4.5, B[4,4,4]=10.5 as given by using the MATLAB code.
Thanks in advance