0
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ A working example would be helpful. $\endgroup$
    – Mr.Wizard
    Commented Sep 9, 2013 at 12:05
  • $\begingroup$ @Mr.Wizard I have added an example, thanks for the suggestion $\endgroup$
    – BillyJean
    Commented Sep 9, 2013 at 12:15

1 Answer 1

5
$\begingroup$

Please tell me if this does what you want:

FindFit[data, a*g[x, 3], a, x]
{a -> 2.}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.