Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15967 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2011-02-01 11:53 +0000 |
| Last post | 2011-02-01 11:53 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: FindFit bug Bill Rowe <readnews@sbcglobal.net> - 2011-02-01 11:53 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2011-02-01 11:53 +0000 |
| Subject | Re: FindFit bug |
| Message-ID | <ii8s8g$2np$1@smc.vnet.net> |
On 1/31/11 at 3:23 AM, igor.volkov@gmail.com (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.
Doing non-linear fitting is inherently difficult. FindFit can
achieve the desired result when the initial starting point is
sufficiently close to the optimum solution. That is
In[10]:= FindFit[dat, a Sin[w t + f], {{a, 2}, {w, 2}, {f, 2}}, t]
Out[10]= {a->3.,w->3.,f->1.}
works. Alternatively, you can have FindFit use NMinimize which
uses other fitting algorithms that work better in some cases.
That is:
In[11]:= FindFit[dat, a Sin[w t + f], {a, w, f}, t,
Method -> "NMinimize"]
Out[11]= {a->-3.,w->-3.,f->-1.}
Note, when you fit to Sin[[3 t+1] you change the problem from a
non-linear problem to a linear problem which has explicit
solutions and should never cause FindFit to have problems.
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web