MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FindFit bug


> It seems that FindFit cannot fit a sine function.
> It produces no warnings and gives a totally
> wrong answer:
> dat = Table[{t, 3 Sin[3 t + 1]}, {t, -3, 3, 0.1}];
> fit = FindFit[dat, a Sin[w t + f], {a, w, f}, t]
> Show[ListPlot[dat], Plot[a Sin[w t + f] /. fit, {t, -3, 3}]]
> Output: {a -> 0.599211, w -> 1.51494, f -> 3.80421}
> At the same time it fits Sin[3t+1] just fine.

Which version are you using? For me it gives a warning with version 8
but not with version 7. In both cases using Method "NMinimize" yields a
correct result:

fit = FindFit[dat, a Sin[w t + f], {a, w, f}, t,
  Method -> "NMinimize"]

It is interesting to see that version 8 finds the parameters with
negative signs when no additional constraints are given (which is of
course also a correct result and you can enforce the positive signs with
an additional constraint)...



  • Prev by Date: Re: Parculiarities of FindRoot
  • Next by Date: Re: FindFit bug
  • Previous by thread: Re: FindFit bug
  • Next by thread: Re: FindFit bug