How can I use Compile to implement recurrence?

I am trying to make the code for the following recurrence. Here wjoin[[i]] is used for calling values from a data set and a is a parameter.

• How can I perform the following recurrence using Compile?
• How can I store the previous values of gg[i] to calculate gg[i + 1]?

I wrote the following code. But it is not working.

gg[1] = a - wjoin[[1]]
gg[2] = (a)*gg[1] - wjoin[[2]])
gg = Compile[{{r1, _Integer}}, 1/(a)*((1 + a )*gg[r1] - wjoin[[r1]])];
gg[3]


Maybe this way?

getgg = Compile[{{a, _Real}, {w, _Real, 1}},
Block[{g},
g = Table[0., {Length[w]}];
g[[1]] = a - w[[1]];
g[[2]] = a g[[1]] - w[[2]];
Do[
g[[i]] = ((1. + a) g[[i - 1]] - w[[i]])/a,
{i, 3, Length[w]}
];
g
],
CompilationTarget -> "C"
];


And then

a = RandomReal[{0, 1}];
w = RandomReal[{0, 1}, 10000];
gg = getgg[a, w];

• ...Thank you for your prompt reply. But this code is not working. – a b Mar 31 '19 at 16:07
• Oh, it does work. The only problem is that quite large numbers appear during the calculations. Numbers that cannot be represented by machine precision numbers. But whether such large numbers appear or not does depend on the values of a and w. Since you did not provide example values, I had to guess. – Henrik Schumacher Mar 31 '19 at 16:10
• It seems that I do have c compiler driver. Can you please help me to inform step by step in this case. I search for this. There are a few posts about this. I am really confused now. – a b Mar 31 '19 at 18:27
• I am also confused. What exactly is the problem? What error messages do you get? You may also try CompilationTarget -> "WVM" instead if you don't have a working C compiler. – Henrik Schumacher Mar 31 '19 at 18:31
• I added the picture with errors – a b Mar 31 '19 at 18:44