Function FITS to data

data = Table[ Sin[x]+0.3(Random[]-0.5),
              {x,0,2Pi,2Pi/100} ] ;

dataplot = ListPlot[ data, PlotStyle-> PointSize[0.005] ];

polyfit = Fit[ data, {1,x,x^2,x^3}, x ]

fitplot = Plot[ polyfit, {x,0,100}, 
                PlotStyle -> Dashing[{0.02,0.02}],
                DisplayFunction -> Identity ] ;

?DisplayFunction

Show[ {dataplot,fitplot},
      DisplayFunction -> $DisplayFunction ] ;

y''[x] == - kappa^2 y[t]

<<Calculus`DSolve`

soln = DSolve[ {y''[x] == - kappa^2 y[x],
                y[0] == 0, y'[0] == 1 },
                y[x], x ]

y[x] /. soln[[1]]

ComplexExpand[%]

theoryfit = Fit[ data, {Sin[x 2 Pi / 100 ],
                        Cos[x 2 Pi / 100 ]}, x ]

fitplot1 = Plot[ theoryfit, {x,0,100},
                 DisplayFunction -> Identity ] ;

Show[ {dataplot, fitplot, fitplot1}, 
       DisplayFunction -> $DisplayFunction ];

<<Statistics`NonlinearFit`

?NonlinearFit

coords = Table[ i, {i,1,100} ] ;

pairdata = Table[ {coords[[i]],data[[i]]}, {i,1,100} ] ;

bestfit = NonlinearFit[ pairdata,
                        p1 Sin[ p2 2Pi x / 100 ],
                        x, {p1,p2} ] // Timing

c1 = Part[bestfit,2,1]

c2 = 100 Part[bestfit,2,2,1,1] / ( 2 Pi )

fitplot2 = Plot[ c1 Sin[ c2 2Pi x / 100 ], {x,0,100},
                 DisplayFunction -> Identity ] ;

Show[ {dataplot, fitplot2}, 
       DisplayFunction -> $DisplayFunction ];