The only difference between my code1 and code2 is the coefficient of Sin is 84.95 in the 1st case and 84.96 in the 2nd, I really wonder why such a small variation makes such a large difference in results.
code1 works perfectly, but code2 produces a fit to the data that is way off from the function used to generate the data.
code1
Clear[nlm, data]
data = Table[{i, 84.96 Sin[2 i] + 50}, {i, 1, 20}];
nlm = NonlinearModelFit[data, a Sin[b x + c] + d, {a, b, c, d}, x]
Show[ListPlot[data], Plot[nlm[x], {x, 0, 20}], Frame -> True]
code2
Clear[nlm, data]
data = Table[{i, 84.95 Sin[2 i] + 50}, {i, 1, 20}];
nlm = NonlinearModelFit[data, a Sin[b x + c] + d, {a, b, c, d}, x]
Show[ListPlot[data], Plot[nlm[x], {x, 0, 20}], Frame -> True]
And it gets even worse at 83 and less. Am I misusing NonlinearModelFit?
