Need help implementing a recurrence relation
Show older comments
I'm trying to code the recurrence relation given below but am having difficulty working out how to implement it. The terms Y(a,b,c,d) are all rational constants (called Newcomb Operators), and a,b,c,d are integers.
4(c+d)Y(a,b,c,d)=2(2b-a)Y(a,b+1,c-1,d)+(b-a)Y(a,b+2,c-2,d)-2(2b+a)Y(a,b-1,c,d-1)-(a+b)Y(a,b-2,c,d-2)+2(2c+2d+2+3a)Y(a,b,c-1,d-1)
The relation is initialised by Y(a,b,0,0)=1 and Y(a,b,c,d)=0 if any of a,b,c,d are negative.
The problem I'm having is that calculating each Y requires values of Y with larger 'b' indices, so I don't think I can just loop through a,b,c,d and calculate each term in turn. I would like to be able to calculate Y values up to the desired limits for a,b,c,d and save them for future use, rather than recalculating them every time I need them. I guess the best way to do this would be a saving them as a 4-dimensional array that could be written to an Excel file- but with 4 indices I'm not sure how to do index this!
Could anyone suggest an approach for tackling this?
Answers (1)
Roger Stafford
on 27 Aug 2014
Edited: Roger Stafford
on 27 Aug 2014
If I interpret your initialization statement correctly, you have
Y(a,b,0,0) = 1
for every non-negative integers a and b. You can take advantage of this in evaluating Y for arbitrarily large b.
As to the parameter a, it doesn't change within the Y's in the recursion formula, so you can consider this as a separate recursion problem for each different a.
I would recommend the following ordering in calling on the recursion formula:
Do this for each a:
for i = 1:N
for j = 1:i
b = i-j;
for k = 0:j % <-- Corrected. The k = 1:j was wrong
c = j-k;
d = k;
Y(a,b,c,d) = 1/(c+d)*(.....)
This way, each of the Y values needed to compute Y(a,b,c,d) will already have been computed provided you make use of your initialization requirements. On exit from the for-loops Y will have been computed for each non-negative integer value of b, c, and d such that b+c+d<=N.
1 Comment
Roger Stafford
on 27 Aug 2014
I have corrected an error in the code I gave you.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!