Re: FindFit bug
- To: mathgroup at smc.vnet.net
- Subject: [mg116095] Re: FindFit bug
- From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
- Date: Wed, 2 Feb 2011 06:06:51 -0500 (EST)
- References: <ii5rhr$fh4$1@smc.vnet.net> <ii8s9u$2ok$1@smc.vnet.net>
A more curious result. I was considering using a simulated annealing approach (for fun) to this, and in order to make the graphics easy, I reduced the number of parameters to two, viz. 3 Sin[w t + f] with parameters w and f. Before trying SA on this, I thought I would just do FindFit. Here are some results: 1) FindFit with no help fit=FindFit[dat,3 Sin[w t+f],{w,f},t] {w->0.6865385392552121`,f->1.3319574051344707`} 2) FindFit with some initial guess fit=FindFit[dat,3 Sin[w t+f],{{w,2},{f,.5}},t] {w->3.`,f->1.0000000000000002`} 3) FindFit with NMinimize, but no initial guess fit=FindFit[dat,3 Sin[w t+f],{{w,2},{f,.5}},t,Method->"NMinimize"] {w->0.05770388710750852`,f->0.025226415829465294`} 4) The surprise, FindFit with NMinimize and the above initial guesses fit=FindFit[dat,3 Sin[w t+f],{{w,2},{f,.5}},t,Method->"NMinimize"] {w->0.05770388710750852`,f->0.025226415829465294`} It seems that the use of NMinimize does not help all the time. Next, I will try SA, but that will be for another post. Kevin On 2/1/2011 6:54 AM, Albert Retey wrote: > Hi, > >> 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)... > > hth, > > albert >