I have a function $g(x, n)$, which is a recursive expression: $x$ is a variable and $n$ the number of iterations. In my case $n=3$ for all $x$. An example is the following:
f[__, 0] = 1;
f[x_, n_] := x*f[x, n - 1]
g[x_, n_] := ArcTan[f[x, n]] + Cos[f[x, n]]/Exp[f[x, n]/100];
data = Table[{i, 2*g[i, 3]}, {i, -3, 3, 0.1}];
I would like to fit a function $a\times g(x,3)$ to the generated data. A succesful fit should give $a=2$. Can I get an example of how to do this in Mathematica?