Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
A working example would be helpful. –  Mr.Wizard Sep 9 '13 at 12:05
    
@Mr.Wizard I have added an example, thanks for the suggestion –  BillyJean Sep 9 '13 at 12:15
add comment

1 Answer

up vote 5 down vote accepted

Please tell me if this does what you want:

FindFit[data, a*g[x, 3], a, x]
{a -> 2.}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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