(*^

::[paletteColors = 128; 
	fontset = title, "New York", 24, L3, center, bold, nohscroll;
	fontset = subtitle, "New York", 18, L2, center, bold, nohscroll;
	fontset = subsubtitle, "New York", 14, L2, center, bold, nohscroll;
	fontset = section, "New York", 14, L2, bold, nohscroll, grayBox;
	fontset = subsection, "New York", 12, L2, bold, nohscroll, blackBox;
	fontset = subsubsection, "New York", 10, L2, bold, nohscroll, whiteBox;
	fontset = text, "New York", 10, L2, nohscroll;
	fontset = smalltext, "New York", 9, L2, nohscroll;
	fontset = input, "Courier", 10, L2, bold, nowordwrap;
	fontset = output, "Courier", 10, L2, nowordwrap;
	fontset = message, "Courier", 10, L2, R65535, nowordwrap;
	fontset = print, "Courier", 10, L2, nowordwrap;
	fontset = info, "Courier", 10, L2, nowordwrap;
	fontset = postscript, "Courier", 12, L2, nowordwrap;
	fontset = name, "Geneva", 10, L2, italic, B65535, nowordwrap, nohscroll;
	fontset = header, "Times", 10, L2;
	fontset = footer, "Times", 12, L2, center;
	fontset = help, "Geneva", 10, L2, nohscroll;
	fontset = clipboard, "New York", 12, L2;
	fontset = completions, "New York", 12, L2, nowordwrap;
	fontset = network, "Courier", 10, L2, nowordwrap;
	fontset = graphlabel, "Courier", 12, L2, nowordwrap;
	fontset = special1, "New York", 12, L2, nowordwrap;
	fontset = special2, "New York", 12, L2, center, nowordwrap;
	fontset = special3, "New York", 12, L2, right, nowordwrap;
	fontset = special4, "New York", 12, L2, nowordwrap;
	fontset = special5, "New York", 12, L2, nowordwrap;]
:[font = section; inactive; ]
Test file for NonlinearFit.m
:[font = input; startGroup; ]
<< NonlinearFit.m
:[font = print; inactive; endGroup; ]
{NonlinearFit}
:[font = input; startGroup; ]
?NonlinearFit
:[font = info; inactive; endGroup; ]
NonlinearFit[data,model,params,vars{,options...}] finds values of params such
   that the expression model fits to data using the Levenberg -  Marquardt
   method. The result is returned as a list of transformation rules analogous
   to Solve. Error estimates appear in the result,too. The meaning of the
   arguments data and vars is the same as in Fit. The argument model is any
   real-valued expression depending on params and vars. params must be a list
   of symbols.
 Supported options: Errors, MaxIterations, InitialGuess, Simplifier,
   ErrorNotation, ProgressTrace; help is available on each.
:[font = subsection; inactive; ]
Create a model with two Gaussian peaks
:[font = input; startGroup; ]
pars = {I1,w1,x1,I2,w2,x2};
pars0 = {1.,0.6,0.,1.5,0.4,1.2};
f[x_,{I1_,w1_,x1_,I2_,w2_,x2_}]=
  I1 Exp[-((x-x1)/w1)^2] + I2 Exp[-((x-x2)/w2)^2]
:[font = output; inactive; output; endGroup; ]
I1/E^((x - x1)^2/w1^2) + I2/E^((x - x2)^2/w2^2)
;[o]
      I1               I2
-------------- + --------------
         2   2            2   2
 (x - x1) /w1     (x - x2) /w2
E                E
:[font = input; ]
plot1 = Plot[f[x,pars0],{x,-1,3},DisplayFunction->Identity];
:[font = subsection; inactive; ]
Data: perturb the original model a little
:[font = input; ]
X = Table[x,{x,-1.,3.,0.1}];
data = {#,f[#,pars0]+Random[Real,{-0.1,0.1}]}& /@ X;
:[font = input; startGroup; ]
plot2 = ListPlot[data,DisplayFunction->Identity];
:[font = subsection; inactive; ]
Do the actual fitting:
:[font = input; startGroup; ]
fitted = 
   NonlinearFit
     [data,f[x,pars],
      pars,x,Errors->0.1,
      InitialGuess->pars0+Table[Random[Real,{-0.2,0.2}]],
        (* give not too easy initial values! *)
      ProgressTrace->True]
:[font = print; inactive; ]
NonlinearFit::trace params = {1.07301, 0.673008, 0.0730085, 1.57301, 
 
   0.473008, 1.27301}, lambda = -1.
:[font = print; inactive; ]
NonlinearFit::trace params = {1.03926, 0.538133, -0.054542, 1.49669, 
 
   0.436424, 1.16087}, lambda = 0.0001.
:[font = print; inactive; ]
NonlinearFit::trace params = {1.06558, 0.568673, -0.017825, 1.51559, 
 
   0.404316, 1.18169}, lambda = 0.00001.
:[font = print; inactive; ]
NonlinearFit::trace params = {1.06754, 0.567771, -0.0179034, 1.51984, 
 
   0.403291, 1.18289}, lambda = 0.000001.
:[font = output; inactive; output; endGroup; endGroup; ]
{I1 -> 1.067485086536382, w1 -> 0.5678847903562003, 
  x1 -> -0.01786283550499441, I2 -> 1.519948561972952, 
  w2 -> 0.4032105109544012, x2 -> 1.182952981504433, 
  Sigma[I1] -> 0.04732741818484616, Sigma[w1] -> 0.03578497841392136, 
  Sigma[x1] -> 0.02282640996856722, Sigma[I2] -> 0.0546603327546067, 
  Sigma[w2] -> 0.0199363047576358, Sigma[x2] -> 0.01376227269383134}
;[o]
{I1 -> 1.06749, w1 -> 0.567885, x1 -> -0.0178628, I2 -> 1.51995, 
 
  w2 -> 0.403211, x2 -> 1.18295, Sigma[I1] -> 0.0473274, 
 
  Sigma[w1] -> 0.035785, Sigma[x1] -> 0.0228264, Sigma[I2] -> 0.0546603, 
 
  Sigma[w2] -> 0.0199363, Sigma[x2] -> 0.0137623}
:[font = input; ]
plot3 = Plot[Release[f[x,pars]/.fitted],{x,-1,3},
             DisplayFunction->Identity,
             PlotStyle->Dashing[{0.01,0.01}]];
:[font = subsection; inactive; ]
and plot it all together:
:[font = input; ]
Show[plot1,plot2,plot3,
     DisplayFunction->$DisplayFunction,
     PlotLabel->"Original model, data and fitted model"];
^*)