summaryrefslogtreecommitdiff
path: root/2048/DEPENDENCIES/recursion.sci
blob: ead807bfb7e1e58aa61c277dda36c502c57aa7aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Recursive computation of Ej and Fj
// 11.1

function [Fj,dFj,Ej,dEj] = recursion(A,dA,C,dC,j)
Fo = C; dFo = dC;
Eo = 1; dEo = 0;
A_z = A(2:dA+1); dA_z = dA-1;
zi = 1; dzi = 0;
for i = 1:j-1
    if (dFo == 0)
        Fn1 = 0;
    else
        Fn1 = Fo(2:(dFo+1));
    end
    dFn1 = max(dFo-1,0);
    Fn2 = -Fo(1)*A_z;  dFn2 = dA-1;
    [Fn,dFn] = poladd(Fn1,dFn1,Fn2,dFn2);
    zi = convol(zi,[0,1]); dzi = dzi + 1;
    En2 = Fn(1)*zi; dEn2 = dzi;
    [En,dEn] = poladd(Eo,dEo,En2,dEn2);
    Eo = En; Fo = Fn;
    dEo = dEn; dFo = dFn;
end
if (dFo == 0)
    Fn1 = 0;
else
Fn1 = Fo(2:(dFo+1));
end;
dFn1 = max(dFo-1,0);
Fn2 = -Fo(1)*A_z;  dFn2 = dA-1;
[Fn,dFn] = poladd(Fn1,dFn1,Fn2,dFn2);
Fj = Fn; dFj = dFn;
Ej = Eo; dEj = dEo;
endfunction;