I'm trying to fit a sinusoidal wave to some numerical data. I can do it by hand using manipulate, so I know roughly the sort of parameter values that I should get back, but functions such as FindFit or NonlinearModel fit are hopeless for some of my datasets.
For example,
data = {0.316228, -0.316228, 0.316228, -0.316228, 0.316228, -0.316228, 0.316228, -0.316228, 0.316228, -0.316228, 0.316228}
FindFit[data, a Sin[bx + c], {a,b,c},x]
FindFit returns
{a -> 0.0687053, b -> 1.13454, c -> 1.04675}
which is hopelessly off. By hand I know I should get something along the lines of
a ~ 0.4,
c ~ -1,
b ~ 3.1
What am I doing wrong?
For other sinusoidal datasets, FindFit works perfectly!
NonlinearModelFit
. Also, you'll find with a bit of digging on this site that nonlinear least squares fits are much more successful when you add better starting guesses. $\endgroup$