Results 1 to 3 of 3

Math Help - A Recursive Function Problem in Mathematica

  1. #1
    Newbie
    Joined
    Jun 2009
    Posts
    2

    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)

    where \beta_{00}=\beta_{0j}=1, \beta_{k1}=1/k!, \beta_{1j}=j

    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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Aug 2008
    Posts
    903
    (didn't need the l= syntax):

    Code:
    In[1397]:= 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, 
       k - n + 1, k}]
    B[3, 3, 3]
    B[2, 3, 3]
    B[4, 4, 4]
    
    Out[1402]= 4
    
    Out[1403]= 9/2
    
    Out[1404]= 21/2
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2009
    Posts
    2
    Quote Originally Posted by shawsend View Post
    (didn't need the l= syntax):

    Code:
    In[1397]:= 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, 
       k - n + 1, k}]
    B[3, 3, 3]
    B[2, 3, 3]
    B[4, 4, 4]
     
    Out[1402]= 4
     
    Out[1403]= 9/2
     
    Out[1404]= 21/2
    Thank you very much, I didn't notice that at all.
    Thank you again.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Primitive Recursive Function
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: December 2nd 2010, 12:24 PM
  2. Definin recursive functions in Mathematica
    Posted in the Math Software Forum
    Replies: 5
    Last Post: January 19th 2010, 11:42 AM
  3. Recursive function
    Posted in the Advanced Math Topics Forum
    Replies: 0
    Last Post: May 20th 2009, 03:00 PM
  4. recursive function
    Posted in the Discrete Math Forum
    Replies: 4
    Last Post: December 7th 2008, 01:50 PM
  5. Recursive Function??
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: October 5th 2008, 07:36 PM

Search Tags


/mathhelpforum @mathhelpforum