Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Math Resources > Mathematics Software Discussion
Reply
 
Thread Tools Display Modes
  #1  
Old June 30th, 2009, 01:18 AM
Newbie
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
David is on a distinguished road
Default 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)=
\left\{
\begin{array}{cc}
1 & a \leq l \leq b\\
0 & \mbox{ otherwise}
\end{array}
\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
Reply With Quote
Advertisement
 
  #2  
Old July 1st, 2009, 04:15 PM
Super Member
 
Join Date: Aug 2008
Posts: 598
Country:
Thanks: 46
Thanked 261 Times in 226 Posts
shawsend is a jewel in the roughshawsend is a jewel in the roughshawsend is a jewel in the roughshawsend is a jewel in the rough
Default

(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
__________________
"I am beset by the ironies in my life"
Reply With Quote
  #3  
Old July 1st, 2009, 04:20 PM
Newbie
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
David is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 02:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.