Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Find fit for sinusoidal data' topicStudent Support Forum > General > "Find fit for sinusoidal data"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
11/28/12 00:33am

Neither the Excel nor the Mathematica do a particularly good fit of the data, but the Mathematica fit is impressively bad. Even trying to give FindFit hints with the starting values of the parameters resists finding a decent fit.

In[1]:= SSdata= {{your data}};
model=b+a Sin[w t+p];

Out[3]= {a-> -0.225031,b->1.01087,w->0.920843,p->13.2377}

In[4]:= Show[ListPlot[SSdata],Plot[model/.badfit,{t,150,180}]]

Out[4]= BadPlotSnipped

Since you have three nice complete cycles in your data and all you want is to fit is a single Sin with offset it is convenient to do one step of what would otherwise be a discrete Fourier transform. By inspection the period is 10 and the "dc offset" is the mean of your y values. The rest comes from multiplying your waveform with Sin and Cos and extracting the needed parameters.

In[5]:= s=Total[Map[Sin[2Pi/10 First[#]]Last[#]&,SSdata]]/(Length[SSdata]/2);
c=Total[Map[Cos[2Pi/10 First[#]]Last[#]&,SSdata]]/(Length[SSdata]/2);goodfit={a->Sqrt[s^2+c^2],b->Mean[Map[Last,SSdata]],w->2Pi/10.,p->ArcTan[s/c]}

Out[6]= {a->1.33146,b->0.99571,w->0.628319,p-> -0.696638}

In[7]:= Show[ListPlot[SSdata],Plot[model/.goodfit,{t,150,180}]]

Out[7]= GoodPlotSnipped

Please check all this carefully for any small dumb mistakes and do not too quickly accept the result. Then thoughtfully consider the larger picture and see if you can justify the theory supporting this.

URL: ,

Subject (listing for 'Find fit for sinusoidal data')
Author Date Posted
Find fit for sinusoidal data Virginia 11/26/12 12:29pm
Re: Find fit for sinusoidal data jf 11/27/12 1:02pm
Re: Find fit for sinusoidal data Bill Simpson 11/28/12 00:33am
< Previous CommentHelp | Reply To Comment | Reply To Topic