(* Exploring non-linear list square fit *) << Statistics`NonlinearFit` F[x_] := 0.5*Exp[0.1*x]; (* define function *) a = .0; b= 20.0; (* define the interpolating interval *) plotfunction = Plot[F[x], {x, a, b+100}, PlotStyle->{Hue[1], Thickness[0.01]}, PlotLabel->"Original function", DisplayFunction -> Identity ] n=20; h = (b-a)/n; (* define data points *) (* data = Table[N[{x, F[x]}], {x, a, b, h}] *) (* now introduce experimental uncertainity *) SeedRandom[] data = Table[N[{x + 0.5*Random[Real, {-1, 1} ], F[x] + 0.5*Random[Real, {-1, 1} ]}], {x, a, b, h}] plotdata = ListPlot[data, PlotLabel -> "Data points", Prolog-> AbsolutePointSize [5] ] (* fit = Fit[data, {1, x, x^2, x^3}, x] (* Do linear least square fit *) *) fit = NonlinearFit[data, alpha*Exp[beta*x], {x}, {alpha, beta} ] (* Do non-linear least square fit *) Print[] Print[fit] plotfit = Plot[fit, {x, a, b+100}, PlotStyle->{Hue[0.5], Thickness[0.005]}, PlotLabel-> "Cubic spline", DisplayFunction -> Identity ] (* Show all graphs at once *) Show[plotfunction, plotdata, plotfit, PlotLabel -> FontForm["red - original f(x), blue - Least S. Fit ", {"Courier", 15}], Prolog-> AbsolutePointSize[5], DisplayFunction -> $DisplayFunction ] (* Show only data and the fit *) (* Show[plotdata, plotfit, PlotLabel -> FontForm["circles - data, blue - Least S. Fit ", {"Courier", 15}], Prolog-> AbsolutePointSize[5], DisplayFunction -> $DisplayFunction ] *) Clear[data] Clear[fit]