Re: FindFit bug
- To: mathgroup at smc.vnet.net
- Subject: [mg116075] Re: FindFit bug
- From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
- Date: Tue, 1 Feb 2011 06:52:31 -0500 (EST)
- References: <ii5rhr$fh4$1@smc.vnet.net>
The problem is that for a nonlinear fit there may be local minima. You
need to give FindFit a reasonably good initial guess. For example
fit = FindFit[dat, a Sin[w t + f], {{a, 2}, w, f}, t]
starts with a at 2, and the result gives the correct answer. I usually
use Manipulate to get a good first guess on the parameters for a 1d
function like this.
Kevin
On 1/31/2011 3:23 AM, Igor wrote:
> Hello,
> 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.
>