How do I implement a recursive function efficiently in MATLAB?

1 reply · 3K views · last reply
EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following equation, and I want to program it using MATLAB. But it is a recursive function, and it seems that I can not handle it well. So please if anyone can help, I will be thankful.

Typeset equations: beta_kj equals the sum over l from k minus N_A plus 1 to k of beta_l(j-1) divided by (k minus l) factorial, times the indicator I of [0, (j-1)(N_A-1)] at l. Below, beta_00 = beta_0j = 1, beta_k1 = 1/k!, beta_1j = j, and I_[a,b](l) is 1 if a ≤ l ≤ b, otherwise 0.
 
Attachments
  • Typeset recursive formula: beta with subscripts k j equals the sum over l from k minus N_A plus 1 to k of beta with subscript l(j-1), divided by (k-l)!, times indicator I of [0,(j-1)(N_A-1)] of l. Below, beta_00 = beta_0j = 1, beta_k1 = 1/k!, beta_1j = j; I_[a,b](l) is 1 if a is at most l at most b, else 0.
    ExpansionFactor.JPG
    10.8 KB · Views: 3,879
I would suggest you create a 2D matrix of size k (whatever that happens to be / you choose it to be--maybe this is a parameter that your function takes in?), seed the initial values given, and then make copious use of the for or while loops in MATLAB:
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f4-1931.html#brbsthm
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f4-1931.html#brbstiw-1
 
Last edited by a moderator: