Re: FindFit bug
- To: mathgroup at smc.vnet.net
- Subject: [mg116093] Re: FindFit bug
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Tue, 1 Feb 2011 06:56:01 -0500 (EST)
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. Very likely has trouble when not given reasonable starting points. Can get around this by using a global method. That would be "NMinimize" since the other possibilities are local optimization methods. In[47]:= fit = FindFit[dat, a Sin[w t + f], {a, w, f}, t, Method -> "NMinimize"] Out[47]= {a -> -3., w -> -3., f -> -1.} I notice that several methods give a result equivalent to yours, so I would guess it is a local minimizer, in the {a,w,f} parameter space, for a sums of squares approximation. Daniel Lichtblau Wolfram Research