(* Exploring non-linear list square fit *) (* To run on command line: math -run "<{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 + 5.1*Random[Real, {-1, 1} ], F[x] + 1.1*Random[Real, {-1, 1} ]}], {x, a, b, h}] plotdata = ListPlot[data, PlotLabel -> "Data points", Prolog-> AbsolutePointSize [5] ] fit = NonlinearModelFit[data, alpha*Exp[beta*x], {alpha, beta}, x] (* Do non-linear least square fit *) Print[] Print[Normal[fit]] plotfit = Plot[fit[x], {x, a, b+20}, PlotStyle->{Hue[0.5], Thickness[0.005]}, PlotLabel-> "Least square", DisplayFunction -> Identity ] 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]